Deprecate old color selection widgets
authorMatthias Clasen <mclasen@redhat.com>
Sat, 4 Feb 2012 01:38:21 +0000 (20:38 -0500)
committerMatthias Clasen <mclasen@redhat.com>
Tue, 14 Feb 2012 21:36:55 +0000 (16:36 -0500)
GtkColorSelectionDialog, GtkColorSelection and GtkHSV have
been superseded by the GtkColorChooser* family of widgets.

20 files changed:
gtk/Makefile.am
gtk/deprecated/gtkcolorsel.c [new file with mode: 0644]
gtk/deprecated/gtkcolorsel.h [new file with mode: 0644]
gtk/deprecated/gtkcolorseldialog.c [new file with mode: 0644]
gtk/deprecated/gtkcolorseldialog.h [new file with mode: 0644]
gtk/deprecated/gtkhsv.c [new file with mode: 0644]
gtk/deprecated/gtkhsv.h [new file with mode: 0644]
gtk/gtk.h
gtk/gtkcolorchooserwidget.c
gtk/gtkcoloreditor.c
gtk/gtkcolorplane.c
gtk/gtkcolorscale.c
gtk/gtkcolorsel.c [deleted file]
gtk/gtkcolorsel.h [deleted file]
gtk/gtkcolorseldialog.c [deleted file]
gtk/gtkcolorseldialog.h [deleted file]
gtk/gtkcolorutils.c [new file with mode: 0644]
gtk/gtkcolorutils.h [new file with mode: 0644]
gtk/gtkhsv.c [deleted file]
gtk/gtkhsv.h [deleted file]

index 9cb3cf550420dbf541ca0f2b266185e9c81e7cdc..6ae0347b6f7193efe1c1635b665c034f49f41667 100644 (file)
@@ -145,6 +145,8 @@ endif
 # by configure)
 
 deprecated_h_sources =                         \
+       deprecated/gtkcolorsel.h        \
+       deprecated/gtkcolorseldialog.h  \
        deprecated/gtkfontsel.h         \
        deprecated/gtkhandlebox.h       \
        deprecated/gtkhbbox.h           \
@@ -153,6 +155,7 @@ deprecated_h_sources =                      \
        deprecated/gtkhscale.h          \
        deprecated/gtkhscrollbar.h      \
        deprecated/gtkhseparator.h      \
+       deprecated/gtkhsv.h             \
        deprecated/gtkstyle.h           \
        deprecated/gtkrc.h              \
        deprecated/gtktable.h           \
@@ -215,11 +218,10 @@ gtk_public_h_sources =            \
        gtkcheckmenuitem.h      \
        gtkclipboard.h          \
        gtkcolorbutton.h        \
-       gtkcolorsel.h           \
-       gtkcolorseldialog.h     \
        gtkcolorchooser.h       \
        gtkcolorchooserwidget.h \
        gtkcolorchooserdialog.h \
+       gtkcolorutils.h         \
        gtkcombobox.h           \
        gtkcomboboxtext.h       \
        gtkcontainer.h          \
@@ -249,7 +251,6 @@ gtk_public_h_sources =              \
        gtkframe.h              \
        gtkgradient.h           \
        gtkgrid.h               \
-       gtkhsv.h                \
        gtkiconfactory.h        \
        gtkicontheme.h          \
        gtkiconview.h           \
@@ -514,6 +515,8 @@ gtk_private_h_sources =             \
 
 # GTK+ C sources to build the library from
 deprecated_c_sources =                         \
+       deprecated/gtkcolorsel.c        \
+       deprecated/gtkcolorseldialog.c  \
        deprecated/gtkfontsel.c         \
        deprecated/gtkhandlebox.c       \
        deprecated/gtkhbbox.c           \
@@ -522,6 +525,7 @@ deprecated_c_sources =                      \
        deprecated/gtkhscale.c          \
        deprecated/gtkhscrollbar.c      \
        deprecated/gtkhseparator.c      \
+       deprecated/gtkhsv.c             \
        deprecated/gtkrc.c              \
        deprecated/gtkstyle.c           \
        deprecated/gtktable.c           \
@@ -598,15 +602,14 @@ gtk_base_c_sources =              \
        gtkcheckbutton.c        \
        gtkcheckmenuitem.c      \
        gtkcolorbutton.c        \
-       gtkcolorsel.c           \
-       gtkcolorseldialog.c     \
+       gtkcolorchooser.c       \
+       gtkcolorchooserwidget.c \
+       gtkcolorchooserdialog.c \
        gtkcoloreditor.c        \
        gtkcolorplane.c         \
        gtkcolorscale.c         \
        gtkcolorswatch.c        \
-       gtkcolorchooser.c       \
-       gtkcolorchooserwidget.c \
-       gtkcolorchooserdialog.c \
+       gtkcolorutils.c         \
        gtkcombobox.c           \
        gtkcomboboxtext.c       \
        gtkcontainer.c          \
@@ -656,7 +659,6 @@ gtk_base_c_sources =                \
        gtkframe.c              \
        gtkgradient.c           \
        gtkgrid.c               \
-       gtkhsv.c                \
        gtkiconcache.c          \
        gtkiconcachevalidator.c \
        gtkiconfactory.c        \
diff --git a/gtk/deprecated/gtkcolorsel.c b/gtk/deprecated/gtkcolorsel.c
new file mode 100644 (file)
index 0000000..813d24c
--- /dev/null
@@ -0,0 +1,3113 @@
+/* GTK - The GIMP Toolkit
+ * Copyright (C) 2000 Red Hat, Inc.
+ * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+/*
+ * Modified by the GTK+ Team and others 1997-2001.  See the AUTHORS
+ * file for a list of people on the GTK+ Team.  See the ChangeLog
+ * files for a list of changes.  These files are distributed with
+ * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
+ */
+
+#include "config.h"
+
+#define GDK_DISABLE_DEPRECATION_WARNINGS
+
+#include "gtkcolorsel.h"
+
+#include <math.h>
+#include <string.h>
+
+#include "gdk/gdk.h"
+#include "gtkorientable.h"
+#include "gtkhsv.h"
+#include "gtkwindow.h"
+#include "gtkselection.h"
+#include "gtkdnd.h"
+#include "gtkdrawingarea.h"
+#include "gtkframe.h"
+#include "gtkgrid.h"
+#include "gtklabel.h"
+#include "gtkmarshalers.h"
+#include "gtkimage.h"
+#include "gtkspinbutton.h"
+#include "gtkrange.h"
+#include "gtkscale.h"
+#include "gtkentry.h"
+#include "gtkbutton.h"
+#include "gtkmenuitem.h"
+#include "gtkmain.h"
+#include "gtksettings.h"
+#include "gtkstock.h"
+#include "gtkaccessible.h"
+#include "gtksizerequest.h"
+#include "gtkseparator.h"
+#include "gtkprivate.h"
+#include "gtkintl.h"
+
+
+/**
+ * SECTION:gtkcolorsel
+ * @Short_description: Deprecated widget used to select a color
+ * @Title: GtkColorSelection
+ *
+ * The #GtkColorSelection is a widget that is used to select
+ * a color.  It consists of a color wheel and number of sliders
+ * and entry boxes for color parameters such as hue, saturation,
+ * value, red, green, blue, and opacity.  It is found on the standard
+ * color selection dialog box #GtkColorSelectionDialog.
+ */
+
+
+/* Keep it in sync with gtksettings.c:default_color_palette */
+#define DEFAULT_COLOR_PALETTE   "black:white:gray50:red:purple:blue:light blue:green:yellow:orange:lavender:brown:goldenrod4:dodger blue:pink:light green:gray10:gray30:gray75:gray90"
+
+/* Number of elements in the custom palatte */
+#define GTK_CUSTOM_PALETTE_WIDTH 10
+#define GTK_CUSTOM_PALETTE_HEIGHT 2
+
+#define CUSTOM_PALETTE_ENTRY_WIDTH   20
+#define CUSTOM_PALETTE_ENTRY_HEIGHT  20
+
+/* The cursor for the dropper */
+#define DROPPER_WIDTH 17
+#define DROPPER_HEIGHT 17
+#define DROPPER_STRIDE (DROPPER_WIDTH * 4)
+#define DROPPER_X_HOT 2
+#define DROPPER_Y_HOT 16
+
+#define SAMPLE_WIDTH  64
+#define SAMPLE_HEIGHT 28
+#define CHECK_SIZE 16
+#define BIG_STEP 20
+
+/* Conversion between 0->1 double and and guint16. See
+ * scale_round() below for more general conversions
+ */
+#define SCALE(i) (i / 65535.)
+#define UNSCALE(d) ((guint16)(d * 65535 + 0.5))
+#define INTENSITY(r, g, b) ((r) * 0.30 + (g) * 0.59 + (b) * 0.11)
+
+enum {
+  COLOR_CHANGED,
+  LAST_SIGNAL
+};
+
+enum {
+  PROP_0,
+  PROP_HAS_PALETTE,
+  PROP_HAS_OPACITY_CONTROL,
+  PROP_CURRENT_COLOR,
+  PROP_CURRENT_ALPHA,
+  PROP_CURRENT_RGBA
+};
+
+enum {
+  COLORSEL_RED = 0,
+  COLORSEL_GREEN = 1,
+  COLORSEL_BLUE = 2,
+  COLORSEL_OPACITY = 3,
+  COLORSEL_HUE,
+  COLORSEL_SATURATION,
+  COLORSEL_VALUE,
+  COLORSEL_NUM_CHANNELS
+};
+
+
+struct _GtkColorSelectionPrivate
+{
+  guint has_opacity       : 1;
+  guint has_palette       : 1;
+  guint changing          : 1;
+  guint default_set       : 1;
+  guint default_alpha_set : 1;
+  guint has_grab          : 1;
+
+  gdouble color[COLORSEL_NUM_CHANNELS];
+  gdouble old_color[COLORSEL_NUM_CHANNELS];
+
+  GtkWidget *triangle_colorsel;
+  GtkWidget *hue_spinbutton;
+  GtkWidget *sat_spinbutton;
+  GtkWidget *val_spinbutton;
+  GtkWidget *red_spinbutton;
+  GtkWidget *green_spinbutton;
+  GtkWidget *blue_spinbutton;
+  GtkWidget *opacity_slider;
+  GtkWidget *opacity_label;
+  GtkWidget *opacity_entry;
+  GtkWidget *palette_frame;
+  GtkWidget *hex_entry;
+
+  /* The Palette code */
+  GtkWidget *custom_palette [GTK_CUSTOM_PALETTE_WIDTH][GTK_CUSTOM_PALETTE_HEIGHT];
+
+  /* The color_sample stuff */
+  GtkWidget *sample_area;
+  GtkWidget *old_sample;
+  GtkWidget *cur_sample;
+  GtkWidget *colorsel;
+
+  /* Window for grabbing on */
+  GtkWidget *dropper_grab_widget;
+  guint32    grab_time;
+  GdkDevice *keyboard_device;
+  GdkDevice *pointer_device;
+
+  /* Connection to settings */
+  gulong settings_connection;
+};
+
+
+static void gtk_color_selection_destroy         (GtkWidget               *widget);
+static void gtk_color_selection_finalize        (GObject                 *object);
+static void update_color                        (GtkColorSelection       *colorsel);
+static void gtk_color_selection_set_property    (GObject                 *object,
+                                                 guint                    prop_id,
+                                                 const GValue            *value,
+                                                 GParamSpec              *pspec);
+static void gtk_color_selection_get_property    (GObject                 *object,
+                                                 guint                    prop_id,
+                                                 GValue                  *value,
+                                                 GParamSpec              *pspec);
+
+static void gtk_color_selection_realize         (GtkWidget               *widget);
+static void gtk_color_selection_unrealize       (GtkWidget               *widget);
+static void gtk_color_selection_show_all        (GtkWidget               *widget);
+static gboolean gtk_color_selection_grab_broken (GtkWidget               *widget,
+                                                 GdkEventGrabBroken      *event);
+
+static void     gtk_color_selection_set_palette_color   (GtkColorSelection *colorsel,
+                                                         gint               index,
+                                                         GdkColor          *color);
+static void     set_focus_line_attributes               (GtkWidget         *drawing_area,
+                                                         cairo_t           *cr,
+                                                         gint              *focus_width);
+static void     default_noscreen_change_palette_func    (const GdkColor    *colors,
+                                                         gint               n_colors);
+static void     default_change_palette_func             (GdkScreen         *screen,
+                                                         const GdkColor    *colors,
+                                                         gint               n_colors);
+static void     make_control_relations                  (AtkObject         *atk_obj,
+                                                         GtkWidget         *widget);
+static void     make_all_relations                      (AtkObject         *atk_obj,
+                                                         GtkColorSelectionPrivate *priv);
+
+static void     hsv_changed                             (GtkWidget         *hsv,
+                                                         gpointer           data);
+static void     get_screen_color                        (GtkWidget         *button);
+static void     adjustment_changed                      (GtkAdjustment     *adjustment,
+                                                         gpointer           data);
+static void     opacity_entry_changed                   (GtkWidget         *opacity_entry,
+                                                         gpointer           data);
+static void     hex_changed                             (GtkWidget         *hex_entry,
+                                                         gpointer           data);
+static gboolean hex_focus_out                           (GtkWidget         *hex_entry,
+                                                         GdkEventFocus     *event,
+                                                         gpointer           data);
+static void     color_sample_new                        (GtkColorSelection *colorsel);
+static void     make_label_spinbutton                   (GtkColorSelection *colorsel,
+                                                         GtkWidget        **spinbutton,
+                                                         gchar             *text,
+                                                         GtkWidget         *table,
+                                                         gint               i,
+                                                         gint               j,
+                                                         gint               channel_type,
+                                                         const gchar       *tooltip);
+static void     make_palette_frame                      (GtkColorSelection *colorsel,
+                                                         GtkWidget         *table,
+                                                         gint               i,
+                                                         gint               j);
+static void     set_selected_palette                    (GtkColorSelection *colorsel,
+                                                         int                x,
+                                                         int                y);
+static void     set_focus_line_attributes               (GtkWidget         *drawing_area,
+                                                         cairo_t           *cr,
+                                                         gint              *focus_width);
+static gboolean mouse_press                             (GtkWidget         *invisible,
+                                                         GdkEventButton    *event,
+                                                         gpointer           data);
+static void  palette_change_notify_instance (GObject    *object,
+                                             GParamSpec *pspec,
+                                             gpointer    data);
+static void update_palette (GtkColorSelection *colorsel);
+static void shutdown_eyedropper (GtkWidget *widget);
+
+static guint color_selection_signals[LAST_SIGNAL] = { 0 };
+
+static GtkColorSelectionChangePaletteFunc noscreen_change_palette_hook = default_noscreen_change_palette_func;
+static GtkColorSelectionChangePaletteWithScreenFunc change_palette_hook = default_change_palette_func;
+
+static const guchar dropper_bits[] = {
+  "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+  "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\377\377\377\377\377\377\377\377\377\377"
+  "\377\377\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+  "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\377\377\377\377\0\0\0\377"
+  "\0\0\0\377\0\0\0\377\377\377\377\377\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+  "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\377\377\377"
+  "\377\0\0\0\377\0\0\0\377\0\0\0\377\0\0\0\377\0\0\0\377\377\377\377\377"
+  "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\377"
+  "\377\377\377\377\377\377\377\377\377\377\377\0\0\0\377\0\0\0\377\0\0"
+  "\0\377\0\0\0\377\0\0\0\377\377\377\377\377\0\0\0\0\0\0\0\0\0\0\0\0\0"
+  "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\377\377\377\377\0\0\0\377\0\0\0\377\0"
+  "\0\0\377\0\0\0\377\0\0\0\377\0\0\0\377\0\0\0\377\0\0\0\377\377\377\377"
+  "\377\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+  "\377\377\377\377\0\0\0\377\0\0\0\377\0\0\0\377\0\0\0\377\0\0\0\377\0"
+  "\0\0\377\377\377\377\377\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+  "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\377\377\377\377\377\0\0\0\377\0\0"
+  "\0\377\0\0\0\377\377\377\377\377\377\377\377\377\0\0\0\0\0\0\0\0\0\0"
+  "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\377\377\377"
+  "\377\377\377\377\377\377\377\377\377\377\0\0\0\377\0\0\0\377\377\377"
+  "\377\377\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+  "\0\0\0\0\0\0\0\0\0\377\377\377\377\377\377\377\377\377\377\377\377\377"
+  "\0\0\0\377\377\377\377\377\0\0\0\377\377\377\377\377\0\0\0\0\0\0\0\0"
+  "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\377\377\377\377"
+  "\377\377\377\377\377\377\377\377\377\0\0\0\377\0\0\0\0\0\0\0\0\377\377"
+  "\377\377\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+  "\0\0\0\0\0\377\377\377\377\377\377\377\377\377\377\377\377\377\0\0\0"
+  "\377\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+  "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\377\377\377\377\377\377\377\377\377\377"
+  "\377\377\377\0\0\0\377\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+  "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\377\377\377\377\377"
+  "\377\377\377\377\377\377\377\377\0\0\0\377\0\0\0\0\0\0\0\0\0\0\0\0\0"
+  "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+  "\377\377\377\377\377\377\377\377\377\377\377\377\377\0\0\0\377\0\0\0"
+  "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+  "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\377\377\377\377\377\377\377\377\377\0\0"
+  "\0\377\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+  "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\377\0\0\0\0\0\0\0\377\0\0\0"
+  "\377\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+  "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\377\0\0\0\0\0"
+  "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+  "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"};
+
+G_DEFINE_TYPE (GtkColorSelection, gtk_color_selection, GTK_TYPE_BOX)
+
+static void
+gtk_color_selection_class_init (GtkColorSelectionClass *klass)
+{
+  GObjectClass *gobject_class;
+  GtkWidgetClass *widget_class;
+
+  gobject_class = G_OBJECT_CLASS (klass);
+  gobject_class->finalize = gtk_color_selection_finalize;
+  gobject_class->set_property = gtk_color_selection_set_property;
+  gobject_class->get_property = gtk_color_selection_get_property;
+
+  widget_class = GTK_WIDGET_CLASS (klass);
+  widget_class->destroy = gtk_color_selection_destroy;
+  widget_class->realize = gtk_color_selection_realize;
+  widget_class->unrealize = gtk_color_selection_unrealize;
+  widget_class->show_all = gtk_color_selection_show_all;
+  widget_class->grab_broken_event = gtk_color_selection_grab_broken;
+
+  g_object_class_install_property (gobject_class,
+                                   PROP_HAS_OPACITY_CONTROL,
+                                   g_param_spec_boolean ("has-opacity-control",
+                                                         P_("Has Opacity Control"),
+                                                         P_("Whether the color selector should allow setting opacity"),
+                                                         FALSE,
+                                                         GTK_PARAM_READWRITE));
+  g_object_class_install_property (gobject_class,
+                                   PROP_HAS_PALETTE,
+                                   g_param_spec_boolean ("has-palette",
+                                                         P_("Has palette"),
+                                                         P_("Whether a palette should be used"),
+                                                         FALSE,
+                                                         GTK_PARAM_READWRITE));
+
+  /**
+   * GtkColorSelection:current-color
+   *
+   * The current GdkColor color.
+   *
+   * Deprecated: 3.4: Use #GtkColorSelection:current-rgba instead.
+   */
+  g_object_class_install_property (gobject_class,
+                                   PROP_CURRENT_COLOR,
+                                   g_param_spec_boxed ("current-color",
+                                                       P_("Current Color"),
+                                                       P_("The current color"),
+                                                       GDK_TYPE_COLOR,
+                                                       GTK_PARAM_READWRITE | G_PARAM_DEPRECATED));
+  g_object_class_install_property (gobject_class,
+                                   PROP_CURRENT_ALPHA,
+                                   g_param_spec_uint ("current-alpha",
+                                                      P_("Current Alpha"),
+                                                      P_("The current opacity value (0 fully transparent, 65535 fully opaque)"),
+                                                      0, 65535, 65535,
+                                                      GTK_PARAM_READWRITE));
+
+  /**
+   * GtkColorSelection:current-rgba
+   *
+   * The current RGBA color.
+   *
+   * Since: 3.0
+   */
+  g_object_class_install_property (gobject_class,
+                                   PROP_CURRENT_RGBA,
+                                   g_param_spec_boxed ("current-rgba",
+                                                       P_("Current RGBA"),
+                                                       P_("The current RGBA color"),
+                                                       GDK_TYPE_RGBA,
+                                                       GTK_PARAM_READWRITE));
+
+  /**
+   * GtkColorSelection::color-changed:
+   * @colorselection: the object which received the signal.
+   *
+   * This signal is emitted when the color changes in the #GtkColorSelection
+   * according to its update policy.
+   */
+  color_selection_signals[COLOR_CHANGED] =
+    g_signal_new (I_("color-changed"),
+                  G_OBJECT_CLASS_TYPE (gobject_class),
+                  G_SIGNAL_RUN_FIRST,
+                  G_STRUCT_OFFSET (GtkColorSelectionClass, color_changed),
+                  NULL, NULL,
+                  _gtk_marshal_VOID__VOID,
+                  G_TYPE_NONE, 0);
+
+  g_type_class_add_private (gobject_class, sizeof (GtkColorSelectionPrivate));
+}
+
+static void
+gtk_color_selection_init (GtkColorSelection *colorsel)
+{
+  GtkWidget *top_hbox;
+  GtkWidget *top_right_vbox;
+  GtkWidget *table, *label, *hbox, *frame, *vbox, *button;
+  GtkAdjustment *adjust;
+  GtkWidget *picker_image;
+  gint i, j;
+  GtkColorSelectionPrivate *priv;
+  AtkObject *atk_obj;
+  GList *focus_chain = NULL;
+
+  gtk_orientable_set_orientation (GTK_ORIENTABLE (colorsel),
+                                  GTK_ORIENTATION_VERTICAL);
+
+  gtk_widget_push_composite_child ();
+
+  priv = colorsel->private_data = G_TYPE_INSTANCE_GET_PRIVATE (colorsel, GTK_TYPE_COLOR_SELECTION, GtkColorSelectionPrivate);
+  priv->changing = FALSE;
+  priv->default_set = FALSE;
+  priv->default_alpha_set = FALSE;
+
+  top_hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 12);
+  gtk_box_pack_start (GTK_BOX (colorsel), top_hbox, FALSE, FALSE, 0);
+
+  vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6);
+  priv->triangle_colorsel = gtk_hsv_new ();
+  g_signal_connect (priv->triangle_colorsel, "changed",
+                    G_CALLBACK (hsv_changed), colorsel);
+  gtk_hsv_set_metrics (GTK_HSV (priv->triangle_colorsel), 174, 15);
+  gtk_box_pack_start (GTK_BOX (top_hbox), vbox, FALSE, FALSE, 0);
+  gtk_box_pack_start (GTK_BOX (vbox), priv->triangle_colorsel, FALSE, FALSE, 0);
+  gtk_widget_set_tooltip_text (priv->triangle_colorsel,
+                        _("Select the color you want from the outer ring. "
+                          "Select the darkness or lightness of that color "
+                          "using the inner triangle."));
+
+  hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
+  gtk_box_pack_end (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
+
+  frame = gtk_frame_new (NULL);
+  gtk_widget_set_size_request (frame, -1, 30);
+  gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_IN);
+  color_sample_new (colorsel);
+  gtk_container_add (GTK_CONTAINER (frame), priv->sample_area);
+  gtk_box_pack_start (GTK_BOX (hbox), frame, TRUE, TRUE, 0);
+
+  button = gtk_button_new ();
+
+  gtk_widget_set_events (button, GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK);
+  g_object_set_data (G_OBJECT (button), I_("COLORSEL"), colorsel);
+  g_signal_connect (button, "clicked",
+                    G_CALLBACK (get_screen_color), NULL);
+  picker_image = gtk_image_new_from_stock (GTK_STOCK_COLOR_PICKER, GTK_ICON_SIZE_BUTTON);
+  gtk_container_add (GTK_CONTAINER (button), picker_image);
+  gtk_widget_show (GTK_WIDGET (picker_image));
+  gtk_box_pack_end (GTK_BOX (hbox), button, FALSE, FALSE, 0);
+
+  gtk_widget_set_tooltip_text (button,
+                        _("Click the eyedropper, then click a color "
+                          "anywhere on your screen to select that color."));
+
+  top_right_vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6);
+  gtk_box_pack_start (GTK_BOX (top_hbox), top_right_vbox, FALSE, FALSE, 0);
+  table = gtk_grid_new ();
+  gtk_box_pack_start (GTK_BOX (top_right_vbox), table, FALSE, FALSE, 0);
+  gtk_grid_set_row_spacing (GTK_GRID (table), 6);
+  gtk_grid_set_column_spacing (GTK_GRID (table), 12);
+
+  make_label_spinbutton (colorsel, &priv->hue_spinbutton, _("_Hue:"), table, 0, 0, COLORSEL_HUE,
+                         _("Position on the color wheel."));
+  gtk_spin_button_set_wrap (GTK_SPIN_BUTTON (priv->hue_spinbutton), TRUE);
+  make_label_spinbutton (colorsel, &priv->sat_spinbutton, _("S_aturation:"), table, 0, 1, COLORSEL_SATURATION,
+                         _("Intensity of the color."));
+  make_label_spinbutton (colorsel, &priv->val_spinbutton, _("_Value:"), table, 0, 2, COLORSEL_VALUE,
+                         _("Brightness of the color."));
+  make_label_spinbutton (colorsel, &priv->red_spinbutton, _("_Red:"), table, 6, 0, COLORSEL_RED,
+                         _("Amount of red light in the color."));
+  make_label_spinbutton (colorsel, &priv->green_spinbutton, _("_Green:"), table, 6, 1, COLORSEL_GREEN,
+                         _("Amount of green light in the color."));
+  make_label_spinbutton (colorsel, &priv->blue_spinbutton, _("_Blue:"), table, 6, 2, COLORSEL_BLUE,
+                         _("Amount of blue light in the color."));
+  gtk_grid_attach (GTK_GRID (table), gtk_separator_new (GTK_ORIENTATION_HORIZONTAL), 0, 3, 8, 1);
+
+  priv->opacity_label = gtk_label_new_with_mnemonic (_("Op_acity:"));
+  gtk_widget_set_halign (priv->opacity_label, GTK_ALIGN_START);
+  gtk_widget_set_valign (priv->opacity_label, GTK_ALIGN_CENTER);
+  gtk_grid_attach (GTK_GRID (table), priv->opacity_label, 0, 4, 1, 1);
+  adjust = gtk_adjustment_new (0.0, 0.0, 255.0, 1.0, 1.0, 0.0);
+  g_object_set_data (G_OBJECT (adjust), I_("COLORSEL"), colorsel);
+  priv->opacity_slider = gtk_scale_new (GTK_ORIENTATION_HORIZONTAL, adjust);
+  gtk_widget_set_tooltip_text (priv->opacity_slider,
+                        _("Transparency of the color."));
+  gtk_label_set_mnemonic_widget (GTK_LABEL (priv->opacity_label),
+                                 priv->opacity_slider);
+  gtk_scale_set_draw_value (GTK_SCALE (priv->opacity_slider), FALSE);
+  g_signal_connect (adjust, "value-changed",
+                    G_CALLBACK (adjustment_changed),
+                    GINT_TO_POINTER (COLORSEL_OPACITY));
+  gtk_grid_attach (GTK_GRID (table), priv->opacity_slider, 1, 4, 6, 1);
+  priv->opacity_entry = gtk_entry_new ();
+  gtk_widget_set_tooltip_text (priv->opacity_entry,
+                        _("Transparency of the color."));
+  gtk_widget_set_size_request (priv->opacity_entry, 40, -1);
+
+  g_signal_connect (priv->opacity_entry, "activate",
+                    G_CALLBACK (opacity_entry_changed), colorsel);
+  gtk_grid_attach (GTK_GRID (table), priv->opacity_entry, 7, 4, 1, 1);
+
+  label = gtk_label_new_with_mnemonic (_("Color _name:"));
+  gtk_grid_attach (GTK_GRID (table), label, 0, 5, 1, 1);
+  gtk_widget_set_halign (label, GTK_ALIGN_START);
+  gtk_widget_set_valign (label, GTK_ALIGN_CENTER);
+  priv->hex_entry = gtk_entry_new ();
+
+  gtk_label_set_mnemonic_widget (GTK_LABEL (label), priv->hex_entry);
+
+  g_signal_connect (priv->hex_entry, "activate",
+                    G_CALLBACK (hex_changed), colorsel);
+
+  g_signal_connect (priv->hex_entry, "focus-out-event",
+                    G_CALLBACK (hex_focus_out), colorsel);
+
+  gtk_widget_set_tooltip_text (priv->hex_entry,
+                        _("You can enter an HTML-style hexadecimal color "
+                          "value, or simply a color name such as 'orange' "
+                          "in this entry."));
+
+  gtk_entry_set_width_chars (GTK_ENTRY (priv->hex_entry), 7);
+  gtk_grid_attach (GTK_GRID (table), priv->hex_entry, 1, 5, 4, 1);
+
+  focus_chain = g_list_append (focus_chain, priv->hue_spinbutton);
+  focus_chain = g_list_append (focus_chain, priv->sat_spinbutton);
+  focus_chain = g_list_append (focus_chain, priv->val_spinbutton);
+  focus_chain = g_list_append (focus_chain, priv->red_spinbutton);
+  focus_chain = g_list_append (focus_chain, priv->green_spinbutton);
+  focus_chain = g_list_append (focus_chain, priv->blue_spinbutton);
+  focus_chain = g_list_append (focus_chain, priv->opacity_slider);
+  focus_chain = g_list_append (focus_chain, priv->opacity_entry);
+  focus_chain = g_list_append (focus_chain, priv->hex_entry);
+  gtk_container_set_focus_chain (GTK_CONTAINER (table), focus_chain);
+  g_list_free (focus_chain);
+
+  /* Set up the palette */
+  table = gtk_grid_new ();
+  gtk_grid_set_row_spacing (GTK_GRID (table), 1);
+  gtk_grid_set_column_spacing (GTK_GRID (table), 1);
+  for (i = 0; i < GTK_CUSTOM_PALETTE_WIDTH; i++)
+    {
+      for (j = 0; j < GTK_CUSTOM_PALETTE_HEIGHT; j++)
+        {
+          make_palette_frame (colorsel, table, i, j);
+        }
+    }
+  set_selected_palette (colorsel, 0, 0);
+  priv->palette_frame = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6);
+  label = gtk_label_new_with_mnemonic (_("_Palette:"));
+  gtk_widget_set_halign (label, GTK_ALIGN_START);
+  gtk_widget_set_valign (label, GTK_ALIGN_CENTER);
+  gtk_box_pack_start (GTK_BOX (priv->palette_frame), label, FALSE, FALSE, 0);
+
+  gtk_label_set_mnemonic_widget (GTK_LABEL (label),
+                                 priv->custom_palette[0][0]);
+
+  gtk_box_pack_end (GTK_BOX (top_right_vbox), priv->palette_frame, FALSE, FALSE, 0);
+  gtk_box_pack_start (GTK_BOX (priv->palette_frame), table, FALSE, FALSE, 0);
+
+  gtk_widget_show_all (top_hbox);
+
+  /* hide unused stuff */
+
+  if (priv->has_opacity == FALSE)
+    {
+      gtk_widget_hide (priv->opacity_label);
+      gtk_widget_hide (priv->opacity_slider);
+      gtk_widget_hide (priv->opacity_entry);
+    }
+
+  if (priv->has_palette == FALSE)
+    {
+      gtk_widget_hide (priv->palette_frame);
+    }
+
+  atk_obj = gtk_widget_get_accessible (priv->triangle_colorsel);
+  if (GTK_IS_ACCESSIBLE (atk_obj))
+    {
+      atk_object_set_name (atk_obj, _("Color Wheel"));
+      atk_object_set_role (gtk_widget_get_accessible (GTK_WIDGET (colorsel)), ATK_ROLE_COLOR_CHOOSER);
+      make_all_relations (atk_obj, priv);
+    }
+
+  gtk_widget_pop_composite_child ();
+}
+
+/* GObject methods */
+static void
+gtk_color_selection_finalize (GObject *object)
+{
+  G_OBJECT_CLASS (gtk_color_selection_parent_class)->finalize (object);
+}
+
+static void
+gtk_color_selection_set_property (GObject         *object,
+                                  guint            prop_id,
+                                  const GValue    *value,
+                                  GParamSpec      *pspec)
+{
+  GtkColorSelection *colorsel = GTK_COLOR_SELECTION (object);
+
+  switch (prop_id)
+    {
+    case PROP_HAS_OPACITY_CONTROL:
+      gtk_color_selection_set_has_opacity_control (colorsel,
+                                                   g_value_get_boolean (value));
+      break;
+    case PROP_HAS_PALETTE:
+      gtk_color_selection_set_has_palette (colorsel,
+                                           g_value_get_boolean (value));
+      break;
+    case PROP_CURRENT_COLOR:
+      {
+        GdkColor *color;
+        GdkRGBA rgba;
+
+        color = g_value_get_boxed (value);
+
+        rgba.red = SCALE (color->red);
+        rgba.green = SCALE (color->green);;
+        rgba.blue = SCALE (color->blue);
+        rgba.alpha = 1.0;
+
+        gtk_color_selection_set_current_rgba (colorsel, &rgba);
+      }
+      break;
+    case PROP_CURRENT_ALPHA:
+      gtk_color_selection_set_current_alpha (colorsel, g_value_get_uint (value));
+      break;
+    case PROP_CURRENT_RGBA:
+      gtk_color_selection_set_current_rgba (colorsel, g_value_get_boxed (value));
+      break;
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+      break;
+    }
+
+}
+
+static void
+gtk_color_selection_get_property (GObject     *object,
+                                  guint        prop_id,
+                                  GValue      *value,
+                                  GParamSpec  *pspec)
+{
+  GtkColorSelection *colorsel = GTK_COLOR_SELECTION (object);
+
+  switch (prop_id)
+    {
+    case PROP_HAS_OPACITY_CONTROL:
+      g_value_set_boolean (value, gtk_color_selection_get_has_opacity_control (colorsel));
+      break;
+    case PROP_HAS_PALETTE:
+      g_value_set_boolean (value, gtk_color_selection_get_has_palette (colorsel));
+      break;
+    case PROP_CURRENT_COLOR:
+      {
+        GdkColor color;
+        GdkRGBA rgba;
+
+        gtk_color_selection_get_current_rgba (colorsel, &rgba);
+
+        color.red = UNSCALE (rgba.red);
+        color.green = UNSCALE (rgba.green);
+        color.blue = UNSCALE (rgba.blue);
+
+        g_value_set_boxed (value, &color);
+      }
+      break;
+    case PROP_CURRENT_ALPHA:
+      g_value_set_uint (value, gtk_color_selection_get_current_alpha (colorsel));
+      break;
+    case PROP_CURRENT_RGBA:
+      {
+        GdkRGBA rgba;
+
+        gtk_color_selection_get_current_rgba (colorsel, &rgba);
+        g_value_set_boxed (value, &rgba);
+      }
+      break;
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+      break;
+    }
+}
+
+/* GtkWidget methods */
+
+static void
+gtk_color_selection_destroy (GtkWidget *widget)
+{
+  GtkColorSelection *cselection = GTK_COLOR_SELECTION (widget);
+  GtkColorSelectionPrivate *priv = cselection->private_data;
+
+  if (priv->dropper_grab_widget)
+    {
+      gtk_widget_destroy (priv->dropper_grab_widget);
+      priv->dropper_grab_widget = NULL;
+    }
+
+  GTK_WIDGET_CLASS (gtk_color_selection_parent_class)->destroy (widget);
+}
+
+static void
+gtk_color_selection_realize (GtkWidget *widget)
+{
+  GtkColorSelection *colorsel = GTK_COLOR_SELECTION (widget);
+  GtkColorSelectionPrivate *priv = colorsel->private_data;
+  GtkSettings *settings = gtk_widget_get_settings (widget);
+
+  priv->settings_connection =  g_signal_connect (settings,
+                                                 "notify::gtk-color-palette",
+                                                 G_CALLBACK (palette_change_notify_instance),
+                                                 widget);
+  update_palette (colorsel);
+
+  GTK_WIDGET_CLASS (gtk_color_selection_parent_class)->realize (widget);
+}
+
+static void
+gtk_color_selection_unrealize (GtkWidget *widget)
+{
+  GtkColorSelection *colorsel = GTK_COLOR_SELECTION (widget);
+  GtkColorSelectionPrivate *priv = colorsel->private_data;
+  GtkSettings *settings = gtk_widget_get_settings (widget);
+
+  g_signal_handler_disconnect (settings, priv->settings_connection);
+
+  GTK_WIDGET_CLASS (gtk_color_selection_parent_class)->unrealize (widget);
+}
+
+/* We override show-all since we have internal widgets that
+ * shouldn't be shown when you call show_all(), like the
+ * palette and opacity sliders.
+ */
+static void
+gtk_color_selection_show_all (GtkWidget *widget)
+{
+  gtk_widget_show (widget);
+}
+
+static gboolean
+gtk_color_selection_grab_broken (GtkWidget          *widget,
+                                 GdkEventGrabBroken *event)
+{
+  shutdown_eyedropper (widget);
+
+  return TRUE;
+}
+
+/*
+ *
+ * The Sample Color
+ *
+ */
+
+static void color_sample_draw_sample (GtkColorSelection *colorsel,
+                                      int                which,
+                                      cairo_t *          cr);
+static void color_sample_update_samples (GtkColorSelection *colorsel);
+
+static void
+set_color_internal (GtkColorSelection *colorsel,
+                    gdouble           *color)
+{
+  GtkColorSelectionPrivate *priv;
+  gint i;
+
+  priv = colorsel->private_data;
+  priv->changing = TRUE;
+  priv->color[COLORSEL_RED] = color[0];
+  priv->color[COLORSEL_GREEN] = color[1];
+  priv->color[COLORSEL_BLUE] = color[2];
+  priv->color[COLORSEL_OPACITY] = color[3];
+  gtk_rgb_to_hsv (priv->color[COLORSEL_RED],
+                  priv->color[COLORSEL_GREEN],
+                  priv->color[COLORSEL_BLUE],
+                  &priv->color[COLORSEL_HUE],
+                  &priv->color[COLORSEL_SATURATION],
+                  &priv->color[COLORSEL_VALUE]);
+  if (priv->default_set == FALSE)
+    {
+      for (i = 0; i < COLORSEL_NUM_CHANNELS; i++)
+        priv->old_color[i] = priv->color[i];
+    }
+  priv->default_set = TRUE;
+  priv->default_alpha_set = TRUE;
+  update_color (colorsel);
+}
+
+static void
+set_color_icon (GdkDragContext *context,
+                gdouble        *colors)
+{
+  GdkPixbuf *pixbuf;
+  guint32 pixel;
+
+  pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, FALSE,
+                           8, 48, 32);
+
+  pixel = (((UNSCALE (colors[COLORSEL_RED])   & 0xff00) << 16) |
+           ((UNSCALE (colors[COLORSEL_GREEN]) & 0xff00) << 8) |
+           ((UNSCALE (colors[COLORSEL_BLUE])  & 0xff00)));
+
+  gdk_pixbuf_fill (pixbuf, pixel);
+
+  gtk_drag_set_icon_pixbuf (context, pixbuf, -2, -2);
+  g_object_unref (pixbuf);
+}
+
+static void
+color_sample_drag_begin (GtkWidget      *widget,
+                         GdkDragContext *context,
+                         gpointer        data)
+{
+  GtkColorSelection *colorsel = data;
+  GtkColorSelectionPrivate *priv;
+  gdouble *colsrc;
+
+  priv = colorsel->private_data;
+
+  if (widget == priv->old_sample)
+    colsrc = priv->old_color;
+  else
+    colsrc = priv->color;
+
+  set_color_icon (context, colsrc);
+}
+
+static void
+color_sample_drag_end (GtkWidget      *widget,
+                       GdkDragContext *context,
+                       gpointer        data)
+{
+  g_object_set_data (G_OBJECT (widget), I_("gtk-color-selection-drag-window"), NULL);
+}
+
+static void
+color_sample_drop_handle (GtkWidget        *widget,
+                          GdkDragContext   *context,
+                          gint              x,
+                          gint              y,
+                          GtkSelectionData *selection_data,
+                          guint             info,
+                          guint             time,
+                          gpointer          data)
+{
+  GtkColorSelection *colorsel = data;
+  GtkColorSelectionPrivate *priv;
+  gint length;
+  guint16 *vals;
+  gdouble color[4];
+  priv = colorsel->private_data;
+
+  /* This is currently a guint16 array of the format:
+   * R
+   * G
+   * B
+   * opacity
+   */
+
+  length = gtk_selection_data_get_length (selection_data);
+
+  if (length < 0)
+    return;
+
+  /* We accept drops with the wrong format, since the KDE color
+   * chooser incorrectly drops application/x-color with format 8.
+   */
+  if (length != 8)
+    {
+      g_warning ("Received invalid color data\n");
+      return;
+    }
+
+  vals = (guint16 *) gtk_selection_data_get_data (selection_data);
+
+  if (widget == priv->cur_sample)
+    {
+      color[0] = (gdouble)vals[0] / 0xffff;
+      color[1] = (gdouble)vals[1] / 0xffff;
+      color[2] = (gdouble)vals[2] / 0xffff;
+      color[3] = (gdouble)vals[3] / 0xffff;
+
+      set_color_internal (colorsel, color);
+    }
+}
+
+static void
+color_sample_drag_handle (GtkWidget        *widget,
+                          GdkDragContext   *context,
+                          GtkSelectionData *selection_data,
+                          guint             info,
+                          guint             time,
+                          gpointer          data)
+{
+  GtkColorSelection *colorsel = data;
+  GtkColorSelectionPrivate *priv;
+  guint16 vals[4];
+  gdouble *colsrc;
+
+  priv = colorsel->private_data;
+
+  if (widget == priv->old_sample)
+    colsrc = priv->old_color;
+  else
+    colsrc = priv->color;
+
+  vals[0] = colsrc[COLORSEL_RED] * 0xffff;
+  vals[1] = colsrc[COLORSEL_GREEN] * 0xffff;
+  vals[2] = colsrc[COLORSEL_BLUE] * 0xffff;
+  vals[3] = priv->has_opacity ? colsrc[COLORSEL_OPACITY] * 0xffff : 0xffff;
+
+  gtk_selection_data_set (selection_data,
+                          gdk_atom_intern_static_string ("application/x-color"),
+                          16, (guchar *)vals, 8);
+}
+
+/* which = 0 means draw old sample, which = 1 means draw new */
+static void
+color_sample_draw_sample (GtkColorSelection *colorsel,
+                          int                which,
+                          cairo_t           *cr)
+{
+  GtkWidget *da;
+  gint x, y, goff;
+  GtkColorSelectionPrivate *priv;
+  int width, height;
+
+  g_return_if_fail (colorsel != NULL);
+  priv = colorsel->private_data;
+
+  g_return_if_fail (priv->sample_area != NULL);
+  if (!gtk_widget_is_drawable (priv->sample_area))
+    return;
+
+  if (which == 0)
+    {
+      da = priv->old_sample;
+      goff = 0;
+    }
+  else
+    {
+      GtkAllocation old_sample_allocation;
+
+      da = priv->cur_sample;
+      gtk_widget_get_allocation (priv->old_sample, &old_sample_allocation);
+      goff =  old_sample_allocation.width % 32;
+    }
+
+  /* Below needs tweaking for non-power-of-two */
+  width = gtk_widget_get_allocated_width (da);
+  height = gtk_widget_get_allocated_height (da);
+
+  if (priv->has_opacity)
+    {
+      /* Draw checks in background */
+
+      cairo_set_source_rgb (cr, 0.5, 0.5, 0.5);
+      cairo_rectangle (cr, 0, 0, width, height);
+      cairo_fill (cr);
+
+      cairo_set_source_rgb (cr, 0.75, 0.75, 0.75);
+      for (x = goff & -CHECK_SIZE; x < goff + width; x += CHECK_SIZE)
+        for (y = 0; y < height; y += CHECK_SIZE)
+          if ((x / CHECK_SIZE + y / CHECK_SIZE) % 2 == 0)
+            cairo_rectangle (cr, x - goff, y, CHECK_SIZE, CHECK_SIZE);
+      cairo_fill (cr);
+    }
+
+  if (which == 0)
+    {
+      cairo_set_source_rgba (cr,
+                             priv->old_color[COLORSEL_RED],
+                             priv->old_color[COLORSEL_GREEN],
+                             priv->old_color[COLORSEL_BLUE],
+                             priv->has_opacity ?
+                                priv->old_color[COLORSEL_OPACITY] : 1.0);
+    }
+  else
+    {
+      cairo_set_source_rgba (cr,
+                             priv->color[COLORSEL_RED],
+                             priv->color[COLORSEL_GREEN],
+                             priv->color[COLORSEL_BLUE],
+                             priv->has_opacity ?
+                               priv->color[COLORSEL_OPACITY] : 1.0);
+    }
+
+  cairo_rectangle (cr, 0, 0, width, height);
+  cairo_fill (cr);
+}
+
+
+static void
+color_sample_update_samples (GtkColorSelection *colorsel)
+{
+  GtkColorSelectionPrivate *priv = colorsel->private_data;
+  gtk_widget_queue_draw (priv->old_sample);
+  gtk_widget_queue_draw (priv->cur_sample);
+}
+
+static gboolean
+color_old_sample_draw (GtkWidget         *da,
+                       cairo_t           *cr,
+                       GtkColorSelection *colorsel)
+{
+  color_sample_draw_sample (colorsel, 0, cr);
+  return FALSE;
+}
+
+
+static gboolean
+color_cur_sample_draw (GtkWidget         *da,
+                       cairo_t           *cr,
+                       GtkColorSelection *colorsel)
+{
+  color_sample_draw_sample (colorsel, 1, cr);
+  return FALSE;
+}
+
+static void
+color_sample_setup_dnd (GtkColorSelection *colorsel, GtkWidget *sample)
+{
+  static const GtkTargetEntry targets[] = {
+    { "application/x-color", 0 }
+  };
+  GtkColorSelectionPrivate *priv;
+  priv = colorsel->private_data;
+
+  gtk_drag_source_set (sample,
+                       GDK_BUTTON1_MASK | GDK_BUTTON3_MASK,
+                       targets, 1,
+                       GDK_ACTION_COPY | GDK_ACTION_MOVE);
+
+  g_signal_connect (sample, "drag-begin",
+                    G_CALLBACK (color_sample_drag_begin),
+                    colorsel);
+  if (sample == priv->cur_sample)
+    {
+
+      gtk_drag_dest_set (sample,
+                         GTK_DEST_DEFAULT_HIGHLIGHT |
+                         GTK_DEST_DEFAULT_MOTION |
+                         GTK_DEST_DEFAULT_DROP,
+                         targets, 1,
+                         GDK_ACTION_COPY);
+
+      g_signal_connect (sample, "drag-end",
+                        G_CALLBACK (color_sample_drag_end),
+                        colorsel);
+    }
+
+  g_signal_connect (sample, "drag-data-get",
+                    G_CALLBACK (color_sample_drag_handle),
+                    colorsel);
+  g_signal_connect (sample, "drag-data-received",
+                    G_CALLBACK (color_sample_drop_handle),
+                    colorsel);
+
+}
+
+static void
+update_tooltips (GtkColorSelection *colorsel)
+{
+  GtkColorSelectionPrivate *priv;
+
+  priv = colorsel->private_data;
+
+  if (priv->has_palette == TRUE)
+    {
+      gtk_widget_set_tooltip_text (priv->old_sample,
+        _("The previously-selected color, for comparison to the color "
+          "you're selecting now. You can drag this color to a palette "
+          "entry, or select this color as current by dragging it to the "
+          "other color swatch alongside."));
+
+      gtk_widget_set_tooltip_text (priv->cur_sample,
+        _("The color you've chosen. You can drag this color to a palette "
+          "entry to save it for use in the future."));
+    }
+  else
+    {
+      gtk_widget_set_tooltip_text (priv->old_sample,
+        _("The previously-selected color, for comparison to the color "
+          "you're selecting now."));
+
+      gtk_widget_set_tooltip_text (priv->cur_sample,
+        _("The color you've chosen."));
+    }
+}
+
+static void
+color_sample_new (GtkColorSelection *colorsel)
+{
+  GtkColorSelectionPrivate *priv;
+
+  priv = colorsel->private_data;
+
+  priv->sample_area = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
+  priv->old_sample = gtk_drawing_area_new ();
+  priv->cur_sample = gtk_drawing_area_new ();
+
+  gtk_box_pack_start (GTK_BOX (priv->sample_area), priv->old_sample,
+                      TRUE, TRUE, 0);
+  gtk_box_pack_start (GTK_BOX (priv->sample_area), priv->cur_sample,
+                      TRUE, TRUE, 0);
+
+  g_signal_connect (priv->old_sample, "draw",
+                    G_CALLBACK (color_old_sample_draw),
+                    colorsel);
+  g_signal_connect (priv->cur_sample, "draw",
+                    G_CALLBACK (color_cur_sample_draw),
+                    colorsel);
+
+  color_sample_setup_dnd (colorsel, priv->old_sample);
+  color_sample_setup_dnd (colorsel, priv->cur_sample);
+
+  update_tooltips (colorsel);
+
+  gtk_widget_show_all (priv->sample_area);
+}
+
+
+/* The palette area code */
+
+static void
+palette_get_color (GtkWidget *drawing_area, gdouble *color)
+{
+  gdouble *color_val;
+
+  g_return_if_fail (color != NULL);
+
+  color_val = g_object_get_data (G_OBJECT (drawing_area), "color_val");
+  if (color_val == NULL)
+    {
+      /* Default to white for no good reason */
+      color[0] = 1.0;
+      color[1] = 1.0;
+      color[2] = 1.0;
+      color[3] = 1.0;
+      return;
+    }
+
+  color[0] = color_val[0];
+  color[1] = color_val[1];
+  color[2] = color_val[2];
+  color[3] = 1.0;
+}
+
+static gboolean
+palette_draw (GtkWidget *drawing_area,
+               cairo_t   *cr,
+               gpointer   data)
+{
+  GtkStyleContext *context;
+  gint focus_width;
+  GdkRGBA color;
+
+  context = gtk_widget_get_style_context (drawing_area);
+  gtk_style_context_get_background_color (context, 0, &color);
+  gdk_cairo_set_source_rgba (cr, &color);
+  cairo_paint (cr);
+
+  if (gtk_widget_has_visible_focus (drawing_area))
+    {
+      set_focus_line_attributes (drawing_area, cr, &focus_width);
+
+      cairo_rectangle (cr,
+                       focus_width / 2., focus_width / 2.,
+                       gtk_widget_get_allocated_width (drawing_area) - focus_width,
+                       gtk_widget_get_allocated_height (drawing_area) - focus_width);
+      cairo_stroke (cr);
+    }
+
+  return FALSE;
+}
+
+static void
+set_focus_line_attributes (GtkWidget *drawing_area,
+                           cairo_t   *cr,
+                           gint      *focus_width)
+{
+  gdouble color[4];
+  gint8 *dash_list;
+
+  gtk_widget_style_get (drawing_area,
+                        "focus-line-width", focus_width,
+                        "focus-line-pattern", (gchar *)&dash_list,
+                        NULL);
+
+  palette_get_color (drawing_area, color);
+
+  if (INTENSITY (color[0], color[1], color[2]) > 0.5)
+    cairo_set_source_rgb (cr, 0., 0., 0.);
+  else
+    cairo_set_source_rgb (cr, 1., 1., 1.);
+
+  cairo_set_line_width (cr, *focus_width);
+
+  if (dash_list[0])
+    {
+      gint n_dashes = strlen ((gchar *)dash_list);
+      gdouble *dashes = g_new (gdouble, n_dashes);
+      gdouble total_length = 0;
+      gdouble dash_offset;
+      gint i;
+
+      for (i = 0; i < n_dashes; i++)
+        {
+          dashes[i] = dash_list[i];
+          total_length += dash_list[i];
+        }
+
+      /* The dash offset here aligns the pattern to integer pixels
+       * by starting the dash at the right side of the left border
+       * Negative dash offsets in cairo don't work
+       * (https://bugs.freedesktop.org/show_bug.cgi?id=2729)
+       */
+      dash_offset = - *focus_width / 2.;
+      while (dash_offset < 0)
+        dash_offset += total_length;
+
+      cairo_set_dash (cr, dashes, n_dashes, dash_offset);
+      g_free (dashes);
+    }
+
+  g_free (dash_list);
+}
+
+static void
+palette_drag_begin (GtkWidget      *widget,
+                    GdkDragContext *context,
+                    gpointer        data)
+{
+  gdouble colors[4];
+
+  palette_get_color (widget, colors);
+  set_color_icon (context, colors);
+}
+
+static void
+palette_drag_handle (GtkWidget        *widget,
+                     GdkDragContext   *context,
+                     GtkSelectionData *selection_data,
+                     guint             info,
+                     guint             time,
+                     gpointer          data)
+{
+  guint16 vals[4];
+  gdouble colsrc[4];
+
+  palette_get_color (widget, colsrc);
+
+  vals[0] = colsrc[COLORSEL_RED] * 0xffff;
+  vals[1] = colsrc[COLORSEL_GREEN] * 0xffff;
+  vals[2] = colsrc[COLORSEL_BLUE] * 0xffff;
+  vals[3] = 0xffff;
+
+  gtk_selection_data_set (selection_data,
+                          gdk_atom_intern_static_string ("application/x-color"),
+                          16, (guchar *)vals, 8);
+}
+
+static void
+palette_drag_end (GtkWidget      *widget,
+                  GdkDragContext *context,
+                  gpointer        data)
+{
+  g_object_set_data (G_OBJECT (widget), I_("gtk-color-selection-drag-window"), NULL);
+}
+
+static GdkColor *
+get_current_colors (GtkColorSelection *colorsel)
+{
+  GtkSettings *settings;
+  GdkColor *colors = NULL;
+  gint n_colors = 0;
+  gchar *palette;
+
+  settings = gtk_widget_get_settings (GTK_WIDGET (colorsel));
+  g_object_get (settings, "gtk-color-palette", &palette, NULL);
+
+  if (!gtk_color_selection_palette_from_string (palette, &colors, &n_colors))
+    {
+      gtk_color_selection_palette_from_string (DEFAULT_COLOR_PALETTE,
+                                               &colors,
+                                               &n_colors);
+    }
+  else
+    {
+      /* If there are less colors provided than the number of slots in the
+       * color selection, we fill in the rest from the defaults.
+       */
+      if (n_colors < (GTK_CUSTOM_PALETTE_WIDTH * GTK_CUSTOM_PALETTE_HEIGHT))
+        {
+          GdkColor *tmp_colors = colors;
+          gint tmp_n_colors = n_colors;
+
+          gtk_color_selection_palette_from_string (DEFAULT_COLOR_PALETTE,
+                                                   &colors,
+                                                   &n_colors);
+          memcpy (colors, tmp_colors, sizeof (GdkColor) * tmp_n_colors);
+
+          g_free (tmp_colors);
+        }
+    }
+
+  /* make sure that we fill every slot */
+  g_assert (n_colors == GTK_CUSTOM_PALETTE_WIDTH * GTK_CUSTOM_PALETTE_HEIGHT);
+  g_free (palette);
+
+  return colors;
+}
+
+/* Changes the model color */
+static void
+palette_change_color (GtkWidget         *drawing_area,
+                      GtkColorSelection *colorsel,
+                      gdouble           *color)
+{
+  gint x, y;
+  GtkColorSelectionPrivate *priv;
+  GdkColor gdk_color;
+  GdkColor *current_colors;
+  GdkScreen *screen;
+
+  g_return_if_fail (GTK_IS_COLOR_SELECTION (colorsel));
+  g_return_if_fail (GTK_IS_DRAWING_AREA (drawing_area));
+
+  priv = colorsel->private_data;
+
+  gdk_color.red = UNSCALE (color[0]);
+  gdk_color.green = UNSCALE (color[1]);
+  gdk_color.blue = UNSCALE (color[2]);
+  gdk_color.pixel = 0;
+
+  x = 0;
+  y = 0;                        /* Quiet GCC */
+  while (x < GTK_CUSTOM_PALETTE_WIDTH)
+    {
+      y = 0;
+      while (y < GTK_CUSTOM_PALETTE_HEIGHT)
+        {
+          if (priv->custom_palette[x][y] == drawing_area)
+            goto out;
+
+          ++y;
+        }
+
+      ++x;
+    }
+
+ out:
+
+  g_assert (x < GTK_CUSTOM_PALETTE_WIDTH || y < GTK_CUSTOM_PALETTE_HEIGHT);
+
+  current_colors = get_current_colors (colorsel);
+  current_colors[y * GTK_CUSTOM_PALETTE_WIDTH + x] = gdk_color;
+
+  screen = gtk_widget_get_screen (GTK_WIDGET (colorsel));
+  if (change_palette_hook != default_change_palette_func)
+    (* change_palette_hook) (screen, current_colors,
+                             GTK_CUSTOM_PALETTE_WIDTH * GTK_CUSTOM_PALETTE_HEIGHT);
+  else if (noscreen_change_palette_hook != default_noscreen_change_palette_func)
+    {
+      if (screen != gdk_screen_get_default ())
+        g_warning ("gtk_color_selection_set_change_palette_hook used by "
+                   "widget is not on the default screen.");
+      (* noscreen_change_palette_hook) (current_colors,
+                                        GTK_CUSTOM_PALETTE_WIDTH * GTK_CUSTOM_PALETTE_HEIGHT);
+    }
+  else
+    (* change_palette_hook) (screen, current_colors,
+                             GTK_CUSTOM_PALETTE_WIDTH * GTK_CUSTOM_PALETTE_HEIGHT);
+
+  g_free (current_colors);
+}
+
+/* Changes the view color */
+static void
+palette_set_color (GtkWidget         *drawing_area,
+                   GtkColorSelection *colorsel,
+                   gdouble           *color)
+{
+  gdouble *new_color = g_new (double, 4);
+  GdkRGBA rgba;
+
+  rgba.red = color[0];
+  rgba.green = color[1];
+  rgba.blue = color[2];
+  rgba.alpha = 1;
+
+  gtk_widget_override_background_color (drawing_area, GTK_STATE_FLAG_NORMAL, &rgba);
+
+  if (GPOINTER_TO_INT (g_object_get_data (G_OBJECT (drawing_area), "color_set")) == 0)
+    {
+      static const GtkTargetEntry targets[] = {
+        { "application/x-color", 0 }
+      };
+      gtk_drag_source_set (drawing_area,
+                           GDK_BUTTON1_MASK | GDK_BUTTON3_MASK,
+                           targets, 1,
+                           GDK_ACTION_COPY | GDK_ACTION_MOVE);
+
+      g_signal_connect (drawing_area, "drag-begin",
+                        G_CALLBACK (palette_drag_begin),
+                        colorsel);
+      g_signal_connect (drawing_area, "drag-data-get",
+                        G_CALLBACK (palette_drag_handle),
+                        colorsel);
+
+      g_object_set_data (G_OBJECT (drawing_area), I_("color_set"),
+                         GINT_TO_POINTER (1));
+    }
+
+  new_color[0] = color[0];
+  new_color[1] = color[1];
+  new_color[2] = color[2];
+  new_color[3] = 1.0;
+
+  g_object_set_data_full (G_OBJECT (drawing_area),
+                          I_("color_val"), new_color, (GDestroyNotify)g_free);
+}
+
+static void
+popup_position_func (GtkMenu   *menu,
+                     gint      *x,
+                     gint      *y,
+                     gboolean  *push_in,
+                     gpointer   user_data)
+{
+  GtkAllocation allocation;
+  GtkWidget *widget;
+  GtkRequisition req;
+  gint root_x, root_y;
+  GdkScreen *screen;
+
+  widget = GTK_WIDGET (user_data);
+
+  g_return_if_fail (gtk_widget_get_realized (widget));
+
+  gdk_window_get_origin (gtk_widget_get_window (widget),
+                         &root_x, &root_y);
+
+  gtk_widget_get_preferred_size (GTK_WIDGET (menu),
+                                 &req, NULL);
+  gtk_widget_get_allocation (widget, &allocation);
+
+  /* Put corner of menu centered on color cell */
+  *x = root_x + allocation.width / 2;
+  *y = root_y + allocation.height / 2;
+
+  /* Ensure sanity */
+  screen = gtk_widget_get_screen (widget);
+  *x = CLAMP (*x, 0, MAX (0, gdk_screen_get_width (screen) - req.width));
+  *y = CLAMP (*y, 0, MAX (0, gdk_screen_get_height (screen) - req.height));
+}
+
+static void
+save_color_selected (GtkWidget *menuitem,
+                     gpointer   data)
+{
+  GtkColorSelection *colorsel;
+  GtkWidget *drawing_area;
+  GtkColorSelectionPrivate *priv;
+
+  drawing_area = GTK_WIDGET (data);
+
+  colorsel = GTK_COLOR_SELECTION (g_object_get_data (G_OBJECT (drawing_area),
+                                                     "gtk-color-sel"));
+
+  priv = colorsel->private_data;
+
+  palette_change_color (drawing_area, colorsel, priv->color);
+}
+
+static void
+do_popup (GtkColorSelection *colorsel,
+          GtkWidget         *drawing_area,
+          guint32            timestamp)
+{
+  GtkWidget *menu;
+  GtkWidget *mi;
+
+  g_object_set_data (G_OBJECT (drawing_area),
+                     I_("gtk-color-sel"),
+                     colorsel);
+
+  menu = gtk_menu_new ();
+
+  mi = gtk_menu_item_new_with_mnemonic (_("_Save color here"));
+
+  g_signal_connect (mi, "activate",
+                    G_CALLBACK (save_color_selected),
+                    drawing_area);
+
+  gtk_menu_shell_append (GTK_MENU_SHELL (menu), mi);
+
+  gtk_widget_show_all (mi);
+
+  gtk_menu_popup (GTK_MENU (menu), NULL, NULL,
+                  popup_position_func, drawing_area,
+                  3, timestamp);
+}
+
+
+static gboolean
+palette_enter (GtkWidget        *drawing_area,
+               GdkEventCrossing *event,
+               gpointer        data)
+{
+  g_object_set_data (G_OBJECT (drawing_area),
+                     I_("gtk-colorsel-have-pointer"),
+                     GUINT_TO_POINTER (TRUE));
+
+  return FALSE;
+}
+
+static gboolean
+palette_leave (GtkWidget        *drawing_area,
+               GdkEventCrossing *event,
+               gpointer        data)
+{
+  g_object_set_data (G_OBJECT (drawing_area),
+                     I_("gtk-colorsel-have-pointer"),
+                     NULL);
+
+  return FALSE;
+}
+
+static gboolean
+palette_press (GtkWidget      *drawing_area,
+               GdkEventButton *event,
+               gpointer        data)
+{
+  GtkColorSelection *colorsel = GTK_COLOR_SELECTION (data);
+
+  gtk_widget_grab_focus (drawing_area);
+
+  if (gdk_event_triggers_context_menu ((GdkEvent *) event))
+    {
+      do_popup (colorsel, drawing_area, event->time);
+      return TRUE;
+    }
+
+  return FALSE;
+}
+
+static gboolean
+palette_release (GtkWidget      *drawing_area,
+                 GdkEventButton *event,
+                 gpointer        data)
+{
+  GtkColorSelection *colorsel = GTK_COLOR_SELECTION (data);
+
+  gtk_widget_grab_focus (drawing_area);
+
+  if (event->button == GDK_BUTTON_PRIMARY &&
+      g_object_get_data (G_OBJECT (drawing_area),
+                         "gtk-colorsel-have-pointer") != NULL)
+    {
+      if (GPOINTER_TO_INT (g_object_get_data (G_OBJECT (drawing_area), "color_set")) != 0)
+        {
+          gdouble color[4];
+          palette_get_color (drawing_area, color);
+          set_color_internal (colorsel, color);
+        }
+    }
+
+  return FALSE;
+}
+
+static void
+palette_drop_handle (GtkWidget        *widget,
+                     GdkDragContext   *context,
+                     gint              x,
+                     gint              y,
+                     GtkSelectionData *selection_data,
+                     guint             info,
+                     guint             time,
+                     gpointer          data)
+{
+  GtkColorSelection *colorsel = GTK_COLOR_SELECTION (data);
+  gint length;
+  guint16 *vals;
+  gdouble color[4];
+
+  length = gtk_selection_data_get_length (selection_data);
+
+  if (length < 0)
+    return;
+
+  /* We accept drops with the wrong format, since the KDE color
+   * chooser incorrectly drops application/x-color with format 8.
+   */
+  if (length != 8)
+    {
+      g_warning ("Received invalid color data\n");
+      return;
+    }
+
+  vals = (guint16 *) gtk_selection_data_get_data (selection_data);
+
+  color[0] = (gdouble)vals[0] / 0xffff;
+  color[1] = (gdouble)vals[1] / 0xffff;
+  color[2] = (gdouble)vals[2] / 0xffff;
+  color[3] = (gdouble)vals[3] / 0xffff;
+  palette_change_color (widget, colorsel, color);
+  set_color_internal (colorsel, color);
+}
+
+static gint
+palette_activate (GtkWidget   *widget,
+                  GdkEventKey *event,
+                  gpointer     data)
+{
+  /* should have a drawing area subclass with an activate signal */
+  if ((event->keyval == GDK_KEY_space) ||
+      (event->keyval == GDK_KEY_Return) ||
+      (event->keyval == GDK_KEY_ISO_Enter) ||
+      (event->keyval == GDK_KEY_KP_Enter) ||
+      (event->keyval == GDK_KEY_KP_Space))
+    {
+      if (GPOINTER_TO_INT (g_object_get_data (G_OBJECT (widget), "color_set")) != 0)
+        {
+          gdouble color[4];
+          palette_get_color (widget, color);
+          set_color_internal (GTK_COLOR_SELECTION (data), color);
+        }
+      return TRUE;
+    }
+
+  return FALSE;
+}
+
+static gboolean
+palette_popup (GtkWidget *widget,
+               gpointer   data)
+{
+  GtkColorSelection *colorsel = GTK_COLOR_SELECTION (data);
+
+  do_popup (colorsel, widget, GDK_CURRENT_TIME);
+  return TRUE;
+}
+
+
+static GtkWidget*
+palette_new (GtkColorSelection *colorsel)
+{
+  GtkWidget *retval;
+
+  static const GtkTargetEntry targets[] = {
+    { "application/x-color", 0 }
+  };
+
+  retval = gtk_drawing_area_new ();
+
+  gtk_widget_set_can_focus (retval, TRUE);
+
+  g_object_set_data (G_OBJECT (retval), I_("color_set"), GINT_TO_POINTER (0));
+  gtk_widget_set_events (retval, GDK_BUTTON_PRESS_MASK
+                         | GDK_BUTTON_RELEASE_MASK
+                         | GDK_EXPOSURE_MASK
+                         | GDK_ENTER_NOTIFY_MASK
+                         | GDK_LEAVE_NOTIFY_MASK);
+
+  g_signal_connect (retval, "draw",
+                    G_CALLBACK (palette_draw), colorsel);
+  g_signal_connect (retval, "button-press-event",
+                    G_CALLBACK (palette_press), colorsel);
+  g_signal_connect (retval, "button-release-event",
+                    G_CALLBACK (palette_release), colorsel);
+  g_signal_connect (retval, "enter-notify-event",
+                    G_CALLBACK (palette_enter), colorsel);
+  g_signal_connect (retval, "leave-notify-event",
+                    G_CALLBACK (palette_leave), colorsel);
+  g_signal_connect (retval, "key-press-event",
+                    G_CALLBACK (palette_activate), colorsel);
+  g_signal_connect (retval, "popup-menu",
+                    G_CALLBACK (palette_popup), colorsel);
+
+  gtk_drag_dest_set (retval,
+                     GTK_DEST_DEFAULT_HIGHLIGHT |
+                     GTK_DEST_DEFAULT_MOTION |
+                     GTK_DEST_DEFAULT_DROP,
+                     targets, 1,
+                     GDK_ACTION_COPY);
+
+  g_signal_connect (retval, "drag-end",
+                    G_CALLBACK (palette_drag_end), NULL);
+  g_signal_connect (retval, "drag-data-received",
+                    G_CALLBACK (palette_drop_handle), colorsel);
+
+  gtk_widget_set_tooltip_text (retval,
+    _("Click this palette entry to make it the current color. "
+      "To change this entry, drag a color swatch here or right-click "
+      "it and select \"Save color here.\""));
+  return retval;
+}
+
+
+/* The actual GtkColorSelection widget */
+
+static GdkCursor *
+make_picker_cursor (GdkScreen *screen)
+{
+  GdkCursor *cursor;
+
+  cursor = gdk_cursor_new_from_name (gdk_screen_get_display (screen),
+                                     "color-picker");
+
+  if (!cursor)
+    {
+      GdkPixbuf *pixbuf;
+
+      pixbuf = gdk_pixbuf_new_from_data (dropper_bits,
+                                         GDK_COLORSPACE_RGB, TRUE, 8,
+                                         DROPPER_WIDTH, DROPPER_HEIGHT,
+                                         DROPPER_STRIDE,
+                                         NULL, NULL);
+
+      cursor = gdk_cursor_new_from_pixbuf (gdk_screen_get_display (screen),
+                                           pixbuf,
+                                           DROPPER_X_HOT, DROPPER_Y_HOT);
+
+      g_object_unref (pixbuf);
+    }
+
+  return cursor;
+}
+
+static void
+grab_color_at_pointer (GdkScreen *screen,
+                       GdkDevice *device,
+                       gint       x_root,
+                       gint       y_root,
+                       gpointer   data)
+{
+  GdkPixbuf *pixbuf;
+  guchar *pixels;
+  GtkColorSelection *colorsel = data;
+  GtkColorSelectionPrivate *priv;
+  GdkColor color;
+  GdkWindow *root_window = gdk_screen_get_root_window (screen);
+
+  priv = colorsel->private_data;
+
+  pixbuf = gdk_pixbuf_get_from_window (root_window,
+                                       x_root, y_root,
+                                       1, 1);
+  if (!pixbuf)
+    {
+      gint x, y;
+      GdkWindow *window = gdk_device_get_window_at_position (device, &x, &y);
+      if (!window)
+        return;
+      pixbuf = gdk_pixbuf_get_from_window (window,
+                                           x, y,
+                                           1, 1);
+      if (!pixbuf)
+        return;
+    }
+  pixels = gdk_pixbuf_get_pixels (pixbuf);
+  color.red = pixels[0] * 0x101;
+  color.green = pixels[1] * 0x101;
+  color.blue = pixels[2] * 0x101;
+  g_object_unref (pixbuf);
+
+  priv->color[COLORSEL_RED] = SCALE (color.red);
+  priv->color[COLORSEL_GREEN] = SCALE (color.green);
+  priv->color[COLORSEL_BLUE] = SCALE (color.blue);
+
+  gtk_rgb_to_hsv (priv->color[COLORSEL_RED],
+                  priv->color[COLORSEL_GREEN],
+                  priv->color[COLORSEL_BLUE],
+                  &priv->color[COLORSEL_HUE],
+                  &priv->color[COLORSEL_SATURATION],
+                  &priv->color[COLORSEL_VALUE]);
+
+  update_color (colorsel);
+}
+
+static void
+shutdown_eyedropper (GtkWidget *widget)
+{
+  GtkColorSelection *colorsel;
+  GtkColorSelectionPrivate *priv;
+
+  colorsel = GTK_COLOR_SELECTION (widget);
+  priv = colorsel->private_data;
+
+  if (priv->has_grab)
+    {
+      gdk_device_ungrab (priv->keyboard_device, priv->grab_time);
+      gdk_device_ungrab (priv->pointer_device, priv->grab_time);
+      gtk_device_grab_remove (priv->dropper_grab_widget, priv->pointer_device);
+
+      priv->has_grab = FALSE;
+      priv->keyboard_device = NULL;
+      priv->pointer_device = NULL;
+    }
+}
+
+static void
+mouse_motion (GtkWidget      *invisible,
+              GdkEventMotion *event,
+              gpointer        data)
+{
+  grab_color_at_pointer (gdk_event_get_screen ((GdkEvent *) event),
+                         gdk_event_get_device ((GdkEvent *) event),
+                         event->x_root, event->y_root, data);
+}
+
+static gboolean
+mouse_release (GtkWidget      *invisible,
+               GdkEventButton *event,
+               gpointer        data)
+{
+  /* GtkColorSelection *colorsel = data; */
+
+  if (event->button != GDK_BUTTON_PRIMARY)
+    return FALSE;
+
+  grab_color_at_pointer (gdk_event_get_screen ((GdkEvent *) event),
+                         gdk_event_get_device ((GdkEvent *) event),
+                         event->x_root, event->y_root, data);
+
+  shutdown_eyedropper (GTK_WIDGET (data));
+
+  g_signal_handlers_disconnect_by_func (invisible,
+                                        mouse_motion,
+                                        data);
+  g_signal_handlers_disconnect_by_func (invisible,
+                                        mouse_release,
+                                        data);
+
+  return TRUE;
+}
+
+/* Helper Functions */
+
+static gboolean
+key_press (GtkWidget   *invisible,
+           GdkEventKey *event,
+           gpointer     data)
+{
+  GdkScreen *screen = gdk_event_get_screen ((GdkEvent *) event);
+  GdkDevice *device, *pointer_device;
+  guint state = event->state & gtk_accelerator_get_default_mod_mask ();
+  gint x, y;
+  gint dx, dy;
+
+  device = gdk_event_get_device ((GdkEvent * ) event);
+  pointer_device = gdk_device_get_associated_device (device);
+  gdk_device_get_position (pointer_device, NULL, &x, &y);
+
+  dx = 0;
+  dy = 0;
+
+  switch (event->keyval)
+    {
+    case GDK_KEY_space:
+    case GDK_KEY_Return:
+    case GDK_KEY_ISO_Enter:
+    case GDK_KEY_KP_Enter:
+    case GDK_KEY_KP_Space:
+      grab_color_at_pointer (screen, pointer_device, x, y, data);
+      /* fall through */
+
+    case GDK_KEY_Escape:
+      shutdown_eyedropper (data);
+
+      g_signal_handlers_disconnect_by_func (invisible,
+                                            mouse_press,
+                                            data);
+      g_signal_handlers_disconnect_by_func (invisible,
+                                            key_press,
+                                            data);
+
+      return TRUE;
+
+    case GDK_KEY_Up:
+    case GDK_KEY_KP_Up:
+      dy = state == GDK_MOD1_MASK ? -BIG_STEP : -1;
+      break;
+
+    case GDK_KEY_Down:
+    case GDK_KEY_KP_Down:
+      dy = state == GDK_MOD1_MASK ? BIG_STEP : 1;
+      break;
+
+    case GDK_KEY_Left:
+    case GDK_KEY_KP_Left:
+      dx = state == GDK_MOD1_MASK ? -BIG_STEP : -1;
+      break;
+
+    case GDK_KEY_Right:
+    case GDK_KEY_KP_Right:
+      dx = state == GDK_MOD1_MASK ? BIG_STEP : 1;
+      break;
+
+    default:
+      return FALSE;
+    }
+
+  gdk_device_warp (pointer_device, screen, x + dx, y + dy);
+
+  return TRUE;
+
+}
+
+static gboolean
+mouse_press (GtkWidget      *invisible,
+             GdkEventButton *event,
+             gpointer        data)
+{
+  if (event->type == GDK_BUTTON_PRESS && event->button == GDK_BUTTON_PRIMARY)
+    {
+      g_signal_connect (invisible, "motion-notify-event",
+                        G_CALLBACK (mouse_motion), data);
+      g_signal_connect (invisible, "button-release-event",
+                        G_CALLBACK (mouse_release), data);
+      g_signal_handlers_disconnect_by_func (invisible,
+                                            mouse_press,
+                                            data);
+      g_signal_handlers_disconnect_by_func (invisible,
+                                            key_press,
+                                            data);
+      return TRUE;
+    }
+
+  return FALSE;
+}
+
+/* when the button is clicked */
+static void
+get_screen_color (GtkWidget *button)
+{
+  GtkColorSelection *colorsel = g_object_get_data (G_OBJECT (button), "COLORSEL");
+  GtkColorSelectionPrivate *priv = colorsel->private_data;
+  GdkScreen *screen = gtk_widget_get_screen (GTK_WIDGET (button));
+  GdkDevice *device, *keyb_device, *pointer_device;
+  GdkCursor *picker_cursor;
+  GdkGrabStatus grab_status;
+  GdkWindow *window;
+  GtkWidget *grab_widget, *toplevel;
+
+  guint32 time = gtk_get_current_event_time ();
+
+  device = gtk_get_current_event_device ();
+
+  if (gdk_device_get_source (device) == GDK_SOURCE_KEYBOARD)
+    {
+      keyb_device = device;
+      pointer_device = gdk_device_get_associated_device (device);
+    }
+  else
+    {
+      pointer_device = device;
+      keyb_device = gdk_device_get_associated_device (device);
+    }
+
+  if (priv->dropper_grab_widget == NULL)
+    {
+      grab_widget = gtk_window_new (GTK_WINDOW_POPUP);
+      gtk_window_set_screen (GTK_WINDOW (grab_widget), screen);
+      gtk_window_resize (GTK_WINDOW (grab_widget), 1, 1);
+      gtk_window_move (GTK_WINDOW (grab_widget), -100, -100);
+      gtk_widget_show (grab_widget);
+
+      gtk_widget_add_events (grab_widget,
+                             GDK_BUTTON_RELEASE_MASK | GDK_BUTTON_PRESS_MASK | GDK_POINTER_MOTION_MASK);
+
+      toplevel = gtk_widget_get_toplevel (GTK_WIDGET (colorsel));
+
+      if (GTK_IS_WINDOW (toplevel))
+        {
+          if (gtk_window_has_group (GTK_WINDOW (toplevel)))
+            gtk_window_group_add_window (gtk_window_get_group (GTK_WINDOW (toplevel)),
+                                         GTK_WINDOW (grab_widget));
+        }
+
+      priv->dropper_grab_widget = grab_widget;
+    }
+
+  window = gtk_widget_get_window (priv->dropper_grab_widget);
+
+  if (gdk_device_grab (keyb_device,
+                       window,
+                       GDK_OWNERSHIP_APPLICATION, FALSE,
+                       GDK_KEY_PRESS_MASK | GDK_KEY_RELEASE_MASK,
+                       NULL, time) != GDK_GRAB_SUCCESS)
+    return;
+
+  picker_cursor = make_picker_cursor (screen);
+  grab_status = gdk_device_grab (pointer_device,
+                                 window,
+                                 GDK_OWNERSHIP_APPLICATION,
+                                 FALSE,
+                                 GDK_BUTTON_RELEASE_MASK | GDK_BUTTON_PRESS_MASK | GDK_POINTER_MOTION_MASK,
+                                 picker_cursor,
+                                 time);
+  g_object_unref (picker_cursor);
+
+  if (grab_status != GDK_GRAB_SUCCESS)
+    {
+      gdk_device_ungrab (keyb_device, time);
+      return;
+    }
+
+  gtk_device_grab_add (priv->dropper_grab_widget,
+                       pointer_device,
+                       TRUE);
+
+  priv->grab_time = time;
+  priv->has_grab = TRUE;
+  priv->keyboard_device = keyb_device;
+  priv->pointer_device = pointer_device;
+
+  g_signal_connect (priv->dropper_grab_widget, "button-press-event",
+                    G_CALLBACK (mouse_press), colorsel);
+  g_signal_connect (priv->dropper_grab_widget, "key-press-event",
+                    G_CALLBACK (key_press), colorsel);
+}
+
+static void
+hex_changed (GtkWidget *hex_entry,
+             gpointer   data)
+{
+  GtkColorSelection *colorsel;
+  GtkColorSelectionPrivate *priv;
+  GdkRGBA color;
+  gchar *text;
+
+  colorsel = GTK_COLOR_SELECTION (data);
+  priv = colorsel->private_data;
+
+  if (priv->changing)
+    return;
+
+  text = gtk_editable_get_chars (GTK_EDITABLE (priv->hex_entry), 0, -1);
+  if (gdk_rgba_parse (&color, text))
+    {
+      priv->color[COLORSEL_RED]   = color.red;
+      priv->color[COLORSEL_GREEN] = color.green;
+      priv->color[COLORSEL_BLUE]  = color.blue;
+      gtk_rgb_to_hsv (priv->color[COLORSEL_RED],
+                      priv->color[COLORSEL_GREEN],
+                      priv->color[COLORSEL_BLUE],
+                      &priv->color[COLORSEL_HUE],
+                      &priv->color[COLORSEL_SATURATION],
+                      &priv->color[COLORSEL_VALUE]);
+      update_color (colorsel);
+    }
+  g_free (text);
+}
+
+static gboolean
+hex_focus_out (GtkWidget     *hex_entry,
+               GdkEventFocus *event,
+               gpointer       data)
+{
+  hex_changed (hex_entry, data);
+
+  return FALSE;
+}
+
+static void
+hsv_changed (GtkWidget *hsv,
+             gpointer   data)
+{
+  GtkColorSelection *colorsel;
+  GtkColorSelectionPrivate *priv;
+
+  colorsel = GTK_COLOR_SELECTION (data);
+  priv = colorsel->private_data;
+
+  if (priv->changing)
+    return;
+
+  gtk_hsv_get_color (GTK_HSV (hsv),
+                     &priv->color[COLORSEL_HUE],
+                     &priv->color[COLORSEL_SATURATION],
+                     &priv->color[COLORSEL_VALUE]);
+  gtk_hsv_to_rgb (priv->color[COLORSEL_HUE],
+                  priv->color[COLORSEL_SATURATION],
+                  priv->color[COLORSEL_VALUE],
+                  &priv->color[COLORSEL_RED],
+                  &priv->color[COLORSEL_GREEN],
+                  &priv->color[COLORSEL_BLUE]);
+  update_color (colorsel);
+}
+
+static void
+adjustment_changed (GtkAdjustment *adjustment,
+                    gpointer       data)
+{
+  GtkColorSelection *colorsel;
+  GtkColorSelectionPrivate *priv;
+
+  colorsel = GTK_COLOR_SELECTION (g_object_get_data (G_OBJECT (adjustment), "COLORSEL"));
+  priv = colorsel->private_data;
+
+  if (priv->changing)
+    return;
+
+  switch (GPOINTER_TO_INT (data))
+    {
+    case COLORSEL_SATURATION:
+    case COLORSEL_VALUE:
+      priv->color[GPOINTER_TO_INT (data)] = gtk_adjustment_get_value (adjustment) / 100;
+      gtk_hsv_to_rgb (priv->color[COLORSEL_HUE],
+                      priv->color[COLORSEL_SATURATION],
+                      priv->color[COLORSEL_VALUE],
+                      &priv->color[COLORSEL_RED],
+                      &priv->color[COLORSEL_GREEN],
+                      &priv->color[COLORSEL_BLUE]);
+      break;
+    case COLORSEL_HUE:
+      priv->color[GPOINTER_TO_INT (data)] = gtk_adjustment_get_value (adjustment) / 360;
+      gtk_hsv_to_rgb (priv->color[COLORSEL_HUE],
+                      priv->color[COLORSEL_SATURATION],
+                      priv->color[COLORSEL_VALUE],
+                      &priv->color[COLORSEL_RED],
+                      &priv->color[COLORSEL_GREEN],
+                      &priv->color[COLORSEL_BLUE]);
+      break;
+    case COLORSEL_RED:
+    case COLORSEL_GREEN:
+    case COLORSEL_BLUE:
+      priv->color[GPOINTER_TO_INT (data)] = gtk_adjustment_get_value (adjustment) / 255;
+
+      gtk_rgb_to_hsv (priv->color[COLORSEL_RED],
+                      priv->color[COLORSEL_GREEN],
+                      priv->color[COLORSEL_BLUE],
+                      &priv->color[COLORSEL_HUE],
+                      &priv->color[COLORSEL_SATURATION],
+                      &priv->color[COLORSEL_VALUE]);
+      break;
+    default:
+      priv->color[GPOINTER_TO_INT (data)] = gtk_adjustment_get_value (adjustment) / 255;
+      break;
+    }
+  update_color (colorsel);
+}
+
+static void
+opacity_entry_changed (GtkWidget *opacity_entry,
+                       gpointer   data)
+{
+  GtkColorSelection *colorsel;
+  GtkColorSelectionPrivate *priv;
+  GtkAdjustment *adj;
+  gchar *text;
+
+  colorsel = GTK_COLOR_SELECTION (data);
+  priv = colorsel->private_data;
+
+  if (priv->changing)
+    return;
+
+  text = gtk_editable_get_chars (GTK_EDITABLE (priv->opacity_entry), 0, -1);
+  adj = gtk_range_get_adjustment (GTK_RANGE (priv->opacity_slider));
+  gtk_adjustment_set_value (adj, g_strtod (text, NULL));
+
+  update_color (colorsel);
+
+  g_free (text);
+}
+
+static void
+make_label_spinbutton (GtkColorSelection *colorsel,
+                       GtkWidget        **spinbutton,
+                       gchar             *text,
+                       GtkWidget         *table,
+                       gint               i,
+                       gint               j,
+                       gint               channel_type,
+                       const gchar       *tooltip)
+{
+  GtkWidget *label;
+  GtkAdjustment *adjust;
+
+  if (channel_type == COLORSEL_HUE)
+    {
+      adjust = gtk_adjustment_new (0.0, 0.0, 360.0, 1.0, 1.0, 0.0);
+    }
+  else if (channel_type == COLORSEL_SATURATION ||
+           channel_type == COLORSEL_VALUE)
+    {
+      adjust = gtk_adjustment_new (0.0, 0.0, 100.0, 1.0, 1.0, 0.0);
+    }
+  else
+    {
+      adjust = gtk_adjustment_new (0.0, 0.0, 255.0, 1.0, 1.0, 0.0);
+    }
+  g_object_set_data (G_OBJECT (adjust), I_("COLORSEL"), colorsel);
+  *spinbutton = gtk_spin_button_new (adjust, 10.0, 0);
+
+  gtk_widget_set_tooltip_text (*spinbutton, tooltip);
+
+  g_signal_connect (adjust, "value-changed",
+                    G_CALLBACK (adjustment_changed),
+                    GINT_TO_POINTER (channel_type));
+  label = gtk_label_new_with_mnemonic (text);
+  gtk_label_set_mnemonic_widget (GTK_LABEL (label), *spinbutton);
+
+  gtk_widget_set_halign (label, GTK_ALIGN_START);
+  gtk_widget_set_valign (label, GTK_ALIGN_CENTER);
+  gtk_grid_attach (GTK_GRID (table), label, i, j, 1, 1);
+  gtk_grid_attach (GTK_GRID (table), *spinbutton, i+1, j, 1, 1);
+}
+
+static void
+make_palette_frame (GtkColorSelection *colorsel,
+                    GtkWidget         *table,
+                    gint               i,
+                    gint               j)
+{
+  GtkWidget *frame;
+  GtkColorSelectionPrivate *priv;
+
+  priv = colorsel->private_data;
+  frame = gtk_frame_new (NULL);
+  gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_IN);
+  priv->custom_palette[i][j] = palette_new (colorsel);
+  gtk_widget_set_size_request (priv->custom_palette[i][j], CUSTOM_PALETTE_ENTRY_WIDTH, CUSTOM_PALETTE_ENTRY_HEIGHT);
+  gtk_container_add (GTK_CONTAINER (frame), priv->custom_palette[i][j]);
+  gtk_grid_attach (GTK_GRID (table), frame, i, j, 1, 1);
+}
+
+/* Set the palette entry [x][y] to be the currently selected one. */
+static void
+set_selected_palette (GtkColorSelection *colorsel, int x, int y)
+{
+  GtkColorSelectionPrivate *priv = colorsel->private_data;
+
+  gtk_widget_grab_focus (priv->custom_palette[x][y]);
+}
+
+static double
+scale_round (double val, double factor)
+{
+  val = floor (val * factor + 0.5);
+  val = MAX (val, 0);
+  val = MIN (val, factor);
+  return val;
+}
+
+static void
+update_color (GtkColorSelection *colorsel)
+{
+  GtkColorSelectionPrivate *priv = colorsel->private_data;
+  gchar entryval[12];
+  gchar opacity_text[32];
+  gchar *ptr;
+
+  priv->changing = TRUE;
+  color_sample_update_samples (colorsel);
+
+  gtk_hsv_set_color (GTK_HSV (priv->triangle_colorsel),
+                     priv->color[COLORSEL_HUE],
+                     priv->color[COLORSEL_SATURATION],
+                     priv->color[COLORSEL_VALUE]);
+  gtk_adjustment_set_value (gtk_spin_button_get_adjustment
+                            (GTK_SPIN_BUTTON (priv->hue_spinbutton)),
+                            scale_round (priv->color[COLORSEL_HUE], 360));
+  gtk_adjustment_set_value (gtk_spin_button_get_adjustment
+                            (GTK_SPIN_BUTTON (priv->sat_spinbutton)),
+                            scale_round (priv->color[COLORSEL_SATURATION], 100));
+  gtk_adjustment_set_value (gtk_spin_button_get_adjustment
+                            (GTK_SPIN_BUTTON (priv->val_spinbutton)),
+                            scale_round (priv->color[COLORSEL_VALUE], 100));
+  gtk_adjustment_set_value (gtk_spin_button_get_adjustment
+                            (GTK_SPIN_BUTTON (priv->red_spinbutton)),
+                            scale_round (priv->color[COLORSEL_RED], 255));
+  gtk_adjustment_set_value (gtk_spin_button_get_adjustment
+                            (GTK_SPIN_BUTTON (priv->green_spinbutton)),
+                            scale_round (priv->color[COLORSEL_GREEN], 255));
+  gtk_adjustment_set_value (gtk_spin_button_get_adjustment
+                            (GTK_SPIN_BUTTON (priv->blue_spinbutton)),
+                            scale_round (priv->color[COLORSEL_BLUE], 255));
+  gtk_adjustment_set_value (gtk_range_get_adjustment
+                            (GTK_RANGE (priv->opacity_slider)),
+                            scale_round (priv->color[COLORSEL_OPACITY], 255));
+
+  g_snprintf (opacity_text, 32, "%.0f", scale_round (priv->color[COLORSEL_OPACITY], 255));
+  gtk_entry_set_text (GTK_ENTRY (priv->opacity_entry), opacity_text);
+
+  g_snprintf (entryval, 11, "#%2X%2X%2X",
+              (guint) (scale_round (priv->color[COLORSEL_RED], 255)),
+              (guint) (scale_round (priv->color[COLORSEL_GREEN], 255)),
+              (guint) (scale_round (priv->color[COLORSEL_BLUE], 255)));
+
+  for (ptr = entryval; *ptr; ptr++)
+    if (*ptr == ' ')
+      *ptr = '0';
+  gtk_entry_set_text (GTK_ENTRY (priv->hex_entry), entryval);
+  priv->changing = FALSE;
+
+  g_object_ref (colorsel);
+
+  g_signal_emit (colorsel, color_selection_signals[COLOR_CHANGED], 0);
+
+  g_object_freeze_notify (G_OBJECT (colorsel));
+  g_object_notify (G_OBJECT (colorsel), "current-color");
+  g_object_notify (G_OBJECT (colorsel), "current-alpha");
+  g_object_thaw_notify (G_OBJECT (colorsel));
+
+  g_object_unref (colorsel);
+}
+
+static void
+update_palette (GtkColorSelection *colorsel)
+{
+  GdkColor *current_colors;
+  gint i, j;
+
+  current_colors = get_current_colors (colorsel);
+
+  for (i = 0; i < GTK_CUSTOM_PALETTE_HEIGHT; i++)
+    {
+      for (j = 0; j < GTK_CUSTOM_PALETTE_WIDTH; j++)
+        {
+          gint index;
+
+          index = i * GTK_CUSTOM_PALETTE_WIDTH + j;
+
+          gtk_color_selection_set_palette_color (colorsel,
+                                                 index,
+                                                 &current_colors[index]);
+        }
+    }
+
+  g_free (current_colors);
+}
+
+static void
+palette_change_notify_instance (GObject    *object,
+                                GParamSpec *pspec,
+                                gpointer    data)
+{
+  update_palette (GTK_COLOR_SELECTION (data));
+}
+
+static void
+default_noscreen_change_palette_func (const GdkColor *colors,
+                                      gint            n_colors)
+{
+  default_change_palette_func (gdk_screen_get_default (), colors, n_colors);
+}
+
+static void
+default_change_palette_func (GdkScreen      *screen,
+                             const GdkColor *colors,
+                             gint            n_colors)
+{
+  gchar *str;
+
+  str = gtk_color_selection_palette_to_string (colors, n_colors);
+
+  gtk_settings_set_string_property (gtk_settings_get_for_screen (screen),
+                                    "gtk-color-palette",
+                                    str,
+                                    "gtk_color_selection_palette_to_string");
+
+  g_free (str);
+}
+
+/**
+ * gtk_color_selection_new:
+ *
+ * Creates a new GtkColorSelection.
+ *
+ * Return value: a new #GtkColorSelection
+ */
+GtkWidget *
+gtk_color_selection_new (void)
+{
+  GtkColorSelection *colorsel;
+  GtkColorSelectionPrivate *priv;
+  gdouble color[4];
+  color[0] = 1.0;
+  color[1] = 1.0;
+  color[2] = 1.0;
+  color[3] = 1.0;
+
+  colorsel = g_object_new (GTK_TYPE_COLOR_SELECTION, NULL);
+  priv = colorsel->private_data;
+  set_color_internal (colorsel, color);
+  gtk_color_selection_set_has_opacity_control (colorsel, TRUE);
+
+  /* We want to make sure that default_set is FALSE.
+   * This way the user can still set it.
+   */
+  priv->default_set = FALSE;
+  priv->default_alpha_set = FALSE;
+
+  return GTK_WIDGET (colorsel);
+}
+
+/**
+ * gtk_color_selection_get_has_opacity_control:
+ * @colorsel: a #GtkColorSelection
+ *
+ * Determines whether the colorsel has an opacity control.
+ *
+ * Return value: %TRUE if the @colorsel has an opacity control,
+ *     %FALSE if it does't
+ */
+gboolean
+gtk_color_selection_get_has_opacity_control (GtkColorSelection *colorsel)
+{
+  GtkColorSelectionPrivate *priv;
+
+  g_return_val_if_fail (GTK_IS_COLOR_SELECTION (colorsel), FALSE);
+
+  priv = colorsel->private_data;
+
+  return priv->has_opacity;
+}
+
+/**
+ * gtk_color_selection_set_has_opacity_control:
+ * @colorsel: a #GtkColorSelection
+ * @has_opacity: %TRUE if @colorsel can set the opacity, %FALSE otherwise
+ *
+ * Sets the @colorsel to use or not use opacity.
+ */
+void
+gtk_color_selection_set_has_opacity_control (GtkColorSelection *colorsel,
+                                             gboolean           has_opacity)
+{
+  GtkColorSelectionPrivate *priv;
+
+  g_return_if_fail (GTK_IS_COLOR_SELECTION (colorsel));
+
+  priv = colorsel->private_data;
+  has_opacity = has_opacity != FALSE;
+
+  if (priv->has_opacity != has_opacity)
+    {
+      priv->has_opacity = has_opacity;
+      if (has_opacity)
+        {
+          gtk_widget_show (priv->opacity_slider);
+          gtk_widget_show (priv->opacity_label);
+          gtk_widget_show (priv->opacity_entry);
+        }
+      else
+        {
+          gtk_widget_hide (priv->opacity_slider);
+          gtk_widget_hide (priv->opacity_label);
+          gtk_widget_hide (priv->opacity_entry);
+        }
+      color_sample_update_samples (colorsel);
+
+      g_object_notify (G_OBJECT (colorsel), "has-opacity-control");
+    }
+}
+
+/**
+ * gtk_color_selection_get_has_palette:
+ * @colorsel: a #GtkColorSelection
+ *
+ * Determines whether the color selector has a color palette.
+ *
+ * Return value: %TRUE if the selector has a palette, %FALSE if it hasn't
+ */
+gboolean
+gtk_color_selection_get_has_palette (GtkColorSelection *colorsel)
+{
+  GtkColorSelectionPrivate *priv;
+
+  g_return_val_if_fail (GTK_IS_COLOR_SELECTION (colorsel), FALSE);
+
+  priv = colorsel->private_data;
+
+  return priv->has_palette;
+}
+
+/**
+ * gtk_color_selection_set_has_palette:
+ * @colorsel: a #GtkColorSelection
+ * @has_palette: %TRUE if palette is to be visible, %FALSE otherwise
+ *
+ * Shows and hides the palette based upon the value of @has_palette.
+ */
+void
+gtk_color_selection_set_has_palette (GtkColorSelection *colorsel,
+                                     gboolean           has_palette)
+{
+  GtkColorSelectionPrivate *priv;
+  g_return_if_fail (GTK_IS_COLOR_SELECTION (colorsel));
+
+  priv = colorsel->private_data;
+  has_palette = has_palette != FALSE;
+
+  if (priv->has_palette != has_palette)
+    {
+      priv->has_palette = has_palette;
+      if (has_palette)
+        gtk_widget_show (priv->palette_frame);
+      else
+        gtk_widget_hide (priv->palette_frame);
+
+      update_tooltips (colorsel);
+
+      g_object_notify (G_OBJECT (colorsel), "has-palette");
+    }
+}
+
+/**
+ * gtk_color_selection_set_current_color:
+ * @colorsel: a #GtkColorSelection
+ * @color: a #GdkColor to set the current color with
+ *
+ * Sets the current color to be @color.
+ *
+ * The first time this is called, it will also set
+ * the original color to be @color too.
+ *
+ * Deprecated: 3.4: Use gtk_color_selection_set_current_rgba() instead.
+ */
+void
+gtk_color_selection_set_current_color (GtkColorSelection *colorsel,
+                                       const GdkColor    *color)
+{
+  GtkColorSelectionPrivate *priv;
+  gint i;
+
+  g_return_if_fail (GTK_IS_COLOR_SELECTION (colorsel));
+  g_return_if_fail (color != NULL);
+
+  priv = colorsel->private_data;
+  priv->changing = TRUE;
+  priv->color[COLORSEL_RED] = SCALE (color->red);
+  priv->color[COLORSEL_GREEN] = SCALE (color->green);
+  priv->color[COLORSEL_BLUE] = SCALE (color->blue);
+  gtk_rgb_to_hsv (priv->color[COLORSEL_RED],
+                  priv->color[COLORSEL_GREEN],
+                  priv->color[COLORSEL_BLUE],
+                  &priv->color[COLORSEL_HUE],
+                  &priv->color[COLORSEL_SATURATION],
+                  &priv->color[COLORSEL_VALUE]);
+  if (priv->default_set == FALSE)
+    {
+      for (i = 0; i < COLORSEL_NUM_CHANNELS; i++)
+        priv->old_color[i] = priv->color[i];
+    }
+  priv->default_set = TRUE;
+  update_color (colorsel);
+}
+
+/**
+ * gtk_color_selection_set_current_alpha:
+ * @colorsel: a #GtkColorSelection
+ * @alpha: an integer between 0 and 65535
+ *
+ * Sets the current opacity to be @alpha.
+ *
+ * The first time this is called, it will also set
+ * the original opacity to be @alpha too.
+ */
+void
+gtk_color_selection_set_current_alpha (GtkColorSelection *colorsel,
+                                       guint16            alpha)
+{
+  GtkColorSelectionPrivate *priv;
+  gint i;
+
+  g_return_if_fail (GTK_IS_COLOR_SELECTION (colorsel));
+
+  priv = colorsel->private_data;
+  priv->changing = TRUE;
+  priv->color[COLORSEL_OPACITY] = SCALE (alpha);
+  if (priv->default_alpha_set == FALSE)
+    {
+      for (i = 0; i < COLORSEL_NUM_CHANNELS; i++)
+        priv->old_color[i] = priv->color[i];
+    }
+  priv->default_alpha_set = TRUE;
+  update_color (colorsel);
+}
+
+/**
+ * gtk_color_selection_get_current_color:
+ * @colorsel: a #GtkColorSelection
+ * @color: (out): a #GdkColor to fill in with the current color
+ *
+ * Sets @color to be the current color in the GtkColorSelection widget.
+ *
+ * Deprecated: 3.4: Use gtk_color_selection_get_current_rgba() instead.
+ */
+void
+gtk_color_selection_get_current_color (GtkColorSelection *colorsel,
+                                       GdkColor          *color)
+{
+  GtkColorSelectionPrivate *priv;
+
+  g_return_if_fail (GTK_IS_COLOR_SELECTION (colorsel));
+  g_return_if_fail (color != NULL);
+
+  priv = colorsel->private_data;
+  color->red = UNSCALE (priv->color[COLORSEL_RED]);
+  color->green = UNSCALE (priv->color[COLORSEL_GREEN]);
+  color->blue = UNSCALE (priv->color[COLORSEL_BLUE]);
+}
+
+/**
+ * gtk_color_selection_get_current_alpha:
+ * @colorsel: a #GtkColorSelection
+ *
+ * Returns the current alpha value.
+ *
+ * Return value: an integer between 0 and 65535
+ */
+guint16
+gtk_color_selection_get_current_alpha (GtkColorSelection *colorsel)
+{
+  GtkColorSelectionPrivate *priv;
+
+  g_return_val_if_fail (GTK_IS_COLOR_SELECTION (colorsel), 0);
+
+  priv = colorsel->private_data;
+  return priv->has_opacity ? UNSCALE (priv->color[COLORSEL_OPACITY]) : 65535;
+}
+
+/**
+ * gtk_color_selection_set_previous_color:
+ * @colorsel: a #GtkColorSelection
+ * @color: a #GdkColor to set the previous color with
+ *
+ * Sets the 'previous' color to be @color.
+ *
+ * This function should be called with some hesitations,
+ * as it might seem confusing to have that color change.
+ * Calling gtk_color_selection_set_current_color() will also
+ * set this color the first time it is called.
+ *
+ * Deprecated: 3.4: Use gtk_color_selection_set_previous_rgba() instead.
+ */
+void
+gtk_color_selection_set_previous_color (GtkColorSelection *colorsel,
+                                        const GdkColor    *color)
+{
+  GtkColorSelectionPrivate *priv;
+
+  g_return_if_fail (GTK_IS_COLOR_SELECTION (colorsel));
+  g_return_if_fail (color != NULL);
+
+  priv = colorsel->private_data;
+  priv->changing = TRUE;
+  priv->old_color[COLORSEL_RED] = SCALE (color->red);
+  priv->old_color[COLORSEL_GREEN] = SCALE (color->green);
+  priv->old_color[COLORSEL_BLUE] = SCALE (color->blue);
+  gtk_rgb_to_hsv (priv->old_color[COLORSEL_RED],
+                  priv->old_color[COLORSEL_GREEN],
+                  priv->old_color[COLORSEL_BLUE],
+                  &priv->old_color[COLORSEL_HUE],
+                  &priv->old_color[COLORSEL_SATURATION],
+                  &priv->old_color[COLORSEL_VALUE]);
+  color_sample_update_samples (colorsel);
+  priv->default_set = TRUE;
+  priv->changing = FALSE;
+}
+
+/**
+ * gtk_color_selection_set_previous_alpha:
+ * @colorsel: a #GtkColorSelection
+ * @alpha: an integer between 0 and 65535
+ *
+ * Sets the 'previous' alpha to be @alpha.
+ *
+ * This function should be called with some hesitations,
+ * as it might seem confusing to have that alpha change.
+ */
+void
+gtk_color_selection_set_previous_alpha (GtkColorSelection *colorsel,
+                                        guint16            alpha)
+{
+  GtkColorSelectionPrivate *priv;
+
+  g_return_if_fail (GTK_IS_COLOR_SELECTION (colorsel));
+
+  priv = colorsel->private_data;
+  priv->changing = TRUE;
+  priv->old_color[COLORSEL_OPACITY] = SCALE (alpha);
+  color_sample_update_samples (colorsel);
+  priv->default_alpha_set = TRUE;
+  priv->changing = FALSE;
+}
+
+
+/**
+ * gtk_color_selection_get_previous_color:
+ * @colorsel: a #GtkColorSelection
+ * @color: (out): a #GdkColor to fill in with the original color value
+ *
+ * Fills @color in with the original color value.
+ *
+ * Deprecated: 3.4: Use gtk_color_selection_get_previous_rgba() instead.
+ */
+void
+gtk_color_selection_get_previous_color (GtkColorSelection *colorsel,
+                                        GdkColor           *color)
+{
+  GtkColorSelectionPrivate *priv;
+
+  g_return_if_fail (GTK_IS_COLOR_SELECTION (colorsel));
+  g_return_if_fail (color != NULL);
+
+  priv = colorsel->private_data;
+  color->red = UNSCALE (priv->old_color[COLORSEL_RED]);
+  color->green = UNSCALE (priv->old_color[COLORSEL_GREEN]);
+  color->blue = UNSCALE (priv->old_color[COLORSEL_BLUE]);
+}
+
+/**
+ * gtk_color_selection_get_previous_alpha:
+ * @colorsel: a #GtkColorSelection
+ *
+ * Returns the previous alpha value.
+ *
+ * Return value: an integer between 0 and 65535
+ */
+guint16
+gtk_color_selection_get_previous_alpha (GtkColorSelection *colorsel)
+{
+  GtkColorSelectionPrivate *priv;
+
+  g_return_val_if_fail (GTK_IS_COLOR_SELECTION (colorsel), 0);
+
+  priv = colorsel->private_data;
+  return priv->has_opacity ? UNSCALE (priv->old_color[COLORSEL_OPACITY]) : 65535;
+}
+
+/**
+ * gtk_color_selection_set_current_rgba:
+ * @colorsel: a #GtkColorSelection
+ * @rgba: A #GdkRGBA to set the current color with
+ *
+ * Sets the current color to be @rgba.
+ *
+ * The first time this is called, it will also set
+ * the original color to be @rgba too.
+ *
+ * Since: 3.0
+ */
+void
+gtk_color_selection_set_current_rgba (GtkColorSelection *colorsel,
+                                      const GdkRGBA     *rgba)
+{
+  GtkColorSelectionPrivate *priv;
+  gint i;
+
+  g_return_if_fail (GTK_IS_COLOR_SELECTION (colorsel));
+  g_return_if_fail (rgba != NULL);
+
+  priv = colorsel->private_data;
+  priv->changing = TRUE;
+
+  priv->color[COLORSEL_RED] = CLAMP (rgba->red, 0, 1);
+  priv->color[COLORSEL_GREEN] = CLAMP (rgba->green, 0, 1);
+  priv->color[COLORSEL_BLUE] = CLAMP (rgba->blue, 0, 1);
+  priv->color[COLORSEL_OPACITY] = CLAMP (rgba->alpha, 0, 1);
+
+  gtk_rgb_to_hsv (priv->color[COLORSEL_RED],
+                  priv->color[COLORSEL_GREEN],
+                  priv->color[COLORSEL_BLUE],
+                  &priv->color[COLORSEL_HUE],
+                  &priv->color[COLORSEL_SATURATION],
+                  &priv->color[COLORSEL_VALUE]);
+
+  if (priv->default_set == FALSE)
+    {
+      for (i = 0; i < COLORSEL_NUM_CHANNELS; i++)
+        priv->old_color[i] = priv->color[i];
+    }
+
+  priv->default_set = TRUE;
+  update_color (colorsel);
+}
+
+/**
+ * gtk_color_selection_get_current_rgba:
+ * @colorsel: a #GtkColorSelection
+ * @rgba: (out): a #GdkRGBA to fill in with the current color
+ *
+ * Sets @rgba to be the current color in the GtkColorSelection widget.
+ *
+ * Since: 3.0
+ */
+void
+gtk_color_selection_get_current_rgba (GtkColorSelection *colorsel,
+                                      GdkRGBA           *rgba)
+{
+  GtkColorSelectionPrivate *priv;
+
+  g_return_if_fail (GTK_IS_COLOR_SELECTION (colorsel));
+  g_return_if_fail (rgba != NULL);
+
+  priv = colorsel->private_data;
+  rgba->red = priv->color[COLORSEL_RED];
+  rgba->green = priv->color[COLORSEL_GREEN];
+  rgba->blue = priv->color[COLORSEL_BLUE];
+  rgba->alpha = (priv->has_opacity) ? priv->color[COLORSEL_OPACITY] : 1;
+}
+
+/**
+ * gtk_color_selection_set_previous_rgba:
+ * @colorsel: a #GtkColorSelection
+ * @rgba: a #GdkRGBA to set the previous color with
+ *
+ * Sets the 'previous' color to be @rgba.
+ *
+ * This function should be called with some hesitations,
+ * as it might seem confusing to have that color change.
+ * Calling gtk_color_selection_set_current_rgba() will also
+ * set this color the first time it is called.
+ *
+ * Since: 3.0
+ */
+void
+gtk_color_selection_set_previous_rgba (GtkColorSelection *colorsel,
+                                       const GdkRGBA     *rgba)
+{
+  GtkColorSelectionPrivate *priv;
+
+  g_return_if_fail (GTK_IS_COLOR_SELECTION (colorsel));
+  g_return_if_fail (rgba != NULL);
+
+  priv = colorsel->private_data;
+  priv->changing = TRUE;
+
+  priv->old_color[COLORSEL_RED] = CLAMP (rgba->red, 0, 1);
+  priv->old_color[COLORSEL_GREEN] = CLAMP (rgba->green, 0, 1);
+  priv->old_color[COLORSEL_BLUE] = CLAMP (rgba->blue, 0, 1);
+  priv->old_color[COLORSEL_OPACITY] = CLAMP (rgba->alpha, 0, 1);
+
+  gtk_rgb_to_hsv (priv->old_color[COLORSEL_RED],
+                  priv->old_color[COLORSEL_GREEN],
+                  priv->old_color[COLORSEL_BLUE],
+                  &priv->old_color[COLORSEL_HUE],
+                  &priv->old_color[COLORSEL_SATURATION],
+                  &priv->old_color[COLORSEL_VALUE]);
+
+  color_sample_update_samples (colorsel);
+  priv->default_set = TRUE;
+  priv->changing = FALSE;
+}
+
+/**
+ * gtk_color_selection_get_previous_rgba:
+ * @colorsel: a #GtkColorSelection
+ * @rgba: (out): a #GdkRGBA to fill in with the original color value
+ *
+ * Fills @rgba in with the original color value.
+ *
+ * Since: 3.0
+ */
+void
+gtk_color_selection_get_previous_rgba (GtkColorSelection *colorsel,
+                                       GdkRGBA           *rgba)
+{
+  GtkColorSelectionPrivate *priv;
+
+  g_return_if_fail (GTK_IS_COLOR_SELECTION (colorsel));
+  g_return_if_fail (rgba != NULL);
+
+  priv = colorsel->private_data;
+  rgba->red = priv->old_color[COLORSEL_RED];
+  rgba->green = priv->old_color[COLORSEL_GREEN];
+  rgba->blue = priv->old_color[COLORSEL_BLUE];
+  rgba->alpha = (priv->has_opacity) ? priv->old_color[COLORSEL_OPACITY] : 1;
+}
+
+/**
+ * gtk_color_selection_set_palette_color:
+ * @colorsel: a #GtkColorSelection
+ * @index: the color index of the palette
+ * @color: A #GdkColor to set the palette with
+ *
+ * Sets the palette located at @index to have @color as its color.
+ */
+static void
+gtk_color_selection_set_palette_color (GtkColorSelection *colorsel,
+                                       gint               index,
+                                       GdkColor          *color)
+{
+  GtkColorSelectionPrivate *priv;
+  gint x, y;
+  gdouble col[3];
+
+  g_return_if_fail (GTK_IS_COLOR_SELECTION (colorsel));
+  g_return_if_fail (index >= 0  && index < GTK_CUSTOM_PALETTE_WIDTH*GTK_CUSTOM_PALETTE_HEIGHT);
+
+  x = index % GTK_CUSTOM_PALETTE_WIDTH;
+  y = index / GTK_CUSTOM_PALETTE_WIDTH;
+
+  priv = colorsel->private_data;
+  col[0] = SCALE (color->red);
+  col[1] = SCALE (color->green);
+  col[2] = SCALE (color->blue);
+
+  palette_set_color (priv->custom_palette[x][y], colorsel, col);
+}
+
+/**
+ * gtk_color_selection_is_adjusting:
+ * @colorsel: a #GtkColorSelection
+ *
+ * Gets the current state of the @colorsel.
+ *
+ * Return value: %TRUE if the user is currently dragging
+ *     a color around, and %FALSE if the selection has stopped
+ */
+gboolean
+gtk_color_selection_is_adjusting (GtkColorSelection *colorsel)
+{
+  GtkColorSelectionPrivate *priv;
+
+  g_return_val_if_fail (GTK_IS_COLOR_SELECTION (colorsel), FALSE);
+
+  priv = colorsel->private_data;
+
+  return (gtk_hsv_is_adjusting (GTK_HSV (priv->triangle_colorsel)));
+}
+
+
+/**
+ * gtk_color_selection_palette_from_string:
+ * @str: a string encoding a color palette
+ * @colors: (out) (array length=n_colors): return location for
+ *     allocated array of #GdkColor
+ * @n_colors: return location for length of array
+ *
+ * Parses a color palette string; the string is a colon-separated
+ * list of color names readable by gdk_color_parse().
+ *
+ * Return value: %TRUE if a palette was successfully parsed
+ */
+gboolean
+gtk_color_selection_palette_from_string (const gchar  *str,
+                                         GdkColor    **colors,
+                                         gint         *n_colors)
+{
+  GdkColor *retval;
+  gint count;
+  gchar *p;
+  gchar *start;
+  gchar *copy;
+
+  count = 0;
+  retval = NULL;
+  copy = g_strdup (str);
+
+  start = copy;
+  p = copy;
+  while (TRUE)
+    {
+      if (*p == ':' || *p == '\0')
+        {
+          gboolean done = TRUE;
+
+          if (start == p)
+            {
+              goto failed; /* empty entry */
+            }
+
+          if (*p)
+            {
+              *p = '\0';
+              done = FALSE;
+            }
+
+          retval = g_renew (GdkColor, retval, count + 1);
+          if (!gdk_color_parse (start, retval + count))
+            {
+              goto failed;
+            }
+
+          ++count;
+
+          if (done)
+            break;
+          else
+            start = p + 1;
+        }
+
+      ++p;
+    }
+
+  g_free (copy);
+
+  if (colors)
+    *colors = retval;
+  else
+    g_free (retval);
+
+  if (n_colors)
+    *n_colors = count;
+
+  return TRUE;
+
+ failed:
+  g_free (copy);
+  g_free (retval);
+
+  if (colors)
+    *colors = NULL;
+  if (n_colors)
+    *n_colors = 0;
+
+  return FALSE;
+}
+
+/**
+ * gtk_color_selection_palette_to_string:
+ * @colors: (array length=n_colors): an array of colors
+ * @n_colors: length of the array
+ *
+ * Encodes a palette as a string, useful for persistent storage.
+ *
+ * Return value: allocated string encoding the palette
+ */
+gchar*
+gtk_color_selection_palette_to_string (const GdkColor *colors,
+                                       gint            n_colors)
+{
+  gint i;
+  gchar **strs = NULL;
+  gchar *retval;
+
+  if (n_colors == 0)
+    return g_strdup ("");
+
+  strs = g_new0 (gchar*, n_colors + 1);
+
+  i = 0;
+  while (i < n_colors)
+    {
+      gchar *ptr;
+
+      strs[i] =
+        g_strdup_printf ("#%2X%2X%2X",
+                         colors[i].red / 256,
+                         colors[i].green / 256,
+                         colors[i].blue / 256);
+
+      for (ptr = strs[i]; *ptr; ptr++)
+        if (*ptr == ' ')
+          *ptr = '0';
+
+      ++i;
+    }
+
+  retval = g_strjoinv (":", strs);
+
+  g_strfreev (strs);
+
+  return retval;
+}
+
+/**
+ * gtk_color_selection_set_change_palette_with_screen_hook: (skip)
+ * @func: a function to call when the custom palette needs saving
+ *
+ * Installs a global function to be called whenever the user
+ * tries to modify the palette in a color selection.
+ *
+ * This function should save the new palette contents, and update
+ * the #GtkSettings::gtk-color-palette GtkSettings property so all
+ * GtkColorSelection widgets will be modified.
+ *
+ * Return value: the previous change palette hook (that was replaced)
+ *
+ * Since: 2.2
+ */
+GtkColorSelectionChangePaletteWithScreenFunc
+gtk_color_selection_set_change_palette_with_screen_hook (GtkColorSelectionChangePaletteWithScreenFunc func)
+{
+  GtkColorSelectionChangePaletteWithScreenFunc old;
+
+  old = change_palette_hook;
+
+  change_palette_hook = func;
+
+  return old;
+}
+
+static void
+make_control_relations (AtkObject *atk_obj,
+                        GtkWidget *widget)
+{
+  AtkObject *obj;
+
+  obj = gtk_widget_get_accessible (widget);
+  atk_object_add_relationship (atk_obj, ATK_RELATION_CONTROLLED_BY, obj);
+  atk_object_add_relationship (obj, ATK_RELATION_CONTROLLER_FOR, atk_obj);
+}
+
+static void
+make_all_relations (AtkObject                *atk_obj,
+                    GtkColorSelectionPrivate *priv)
+{
+  make_control_relations (atk_obj, priv->hue_spinbutton);
+  make_control_relations (atk_obj, priv->sat_spinbutton);
+  make_control_relations (atk_obj, priv->val_spinbutton);
+  make_control_relations (atk_obj, priv->red_spinbutton);
+  make_control_relations (atk_obj, priv->green_spinbutton);
+  make_control_relations (atk_obj, priv->blue_spinbutton);
+}
diff --git a/gtk/deprecated/gtkcolorsel.h b/gtk/deprecated/gtkcolorsel.h
new file mode 100644 (file)
index 0000000..9acf9c3
--- /dev/null
@@ -0,0 +1,159 @@
+/* GTK - The GIMP Toolkit
+ * Copyright (C) 2000 Red Hat, Inc.
+ * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+/*
+ * Modified by the GTK+ Team and others 1997-2000.  See the AUTHORS
+ * file for a list of people on the GTK+ Team.  See the ChangeLog
+ * files for a list of changes.  These files are distributed with
+ * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
+ */
+
+#if !defined (__GTK_H_INSIDE__) && !defined (GTK_COMPILATION)
+#error "Only <gtk/gtk.h> can be included directly."
+#endif
+
+#ifndef __GTK_COLOR_SELECTION_H__
+#define __GTK_COLOR_SELECTION_H__
+
+#include <gtk/gtkdialog.h>
+#include <gtk/gtkbox.h>
+
+G_BEGIN_DECLS
+
+#define GTK_TYPE_COLOR_SELECTION                       (gtk_color_selection_get_type ())
+#define GTK_COLOR_SELECTION(obj)                       (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_COLOR_SELECTION, GtkColorSelection))
+#define GTK_COLOR_SELECTION_CLASS(klass)               (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_COLOR_SELECTION, GtkColorSelectionClass))
+#define GTK_IS_COLOR_SELECTION(obj)                    (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_COLOR_SELECTION))
+#define GTK_IS_COLOR_SELECTION_CLASS(klass)            (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_COLOR_SELECTION))
+#define GTK_COLOR_SELECTION_GET_CLASS(obj)              (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_COLOR_SELECTION, GtkColorSelectionClass))
+
+
+typedef struct _GtkColorSelection       GtkColorSelection;
+typedef struct _GtkColorSelectionPrivate  GtkColorSelectionPrivate;
+typedef struct _GtkColorSelectionClass  GtkColorSelectionClass;
+
+typedef void (* GtkColorSelectionChangePaletteFunc) (const GdkColor    *colors,
+                                                     gint               n_colors);
+
+/**
+ * GtkColorSelectionChangePaletteWithScreenFunc:
+ * @screen:
+ * @colors:
+ * @n_colors:
+ *
+ * Since: 2.2
+ */
+typedef void (* GtkColorSelectionChangePaletteWithScreenFunc) (GdkScreen         *screen,
+                                                              const GdkColor    *colors,
+                                                              gint               n_colors);
+
+struct _GtkColorSelection
+{
+  GtkBox parent_instance;
+
+  /* < private_data > */
+  GtkColorSelectionPrivate *private_data;
+};
+
+struct _GtkColorSelectionClass
+{
+  GtkBoxClass parent_class;
+
+  void (*color_changed)        (GtkColorSelection *color_selection);
+
+  /* Padding for future expansion */
+  void (*_gtk_reserved1) (void);
+  void (*_gtk_reserved2) (void);
+  void (*_gtk_reserved3) (void);
+  void (*_gtk_reserved4) (void);
+};
+
+
+/* ColorSelection */
+
+GType      gtk_color_selection_get_type                (void) G_GNUC_CONST;
+GDK_DEPRECATED_FOR(gtk_color_chooser_widget_new)
+GtkWidget *gtk_color_selection_new                     (void);
+GDK_DEPRECATED_FOR(gtk_color_chooser_get_use_alpha)
+gboolean   gtk_color_selection_get_has_opacity_control (GtkColorSelection *colorsel);
+GDK_DEPRECATED_FOR(gtk_color_chooser_set_use_alpha)
+void       gtk_color_selection_set_has_opacity_control (GtkColorSelection *colorsel,
+                                                       gboolean           has_opacity);
+GDK_DEPRECATED
+gboolean   gtk_color_selection_get_has_palette         (GtkColorSelection *colorsel);
+GDK_DEPRECATED
+void       gtk_color_selection_set_has_palette         (GtkColorSelection *colorsel,
+                                                       gboolean           has_palette);
+
+
+GDK_DEPRECATED_FOR(gtk_color_chooser_set_rgba)
+void     gtk_color_selection_set_current_alpha   (GtkColorSelection *colorsel,
+                                                 guint16            alpha);
+GDK_DEPRECATED_FOR(gtk_color_chooser_get_rgba)
+guint16  gtk_color_selection_get_current_alpha   (GtkColorSelection *colorsel);
+GDK_DEPRECATED
+void     gtk_color_selection_set_previous_alpha  (GtkColorSelection *colorsel,
+                                                 guint16            alpha);
+GDK_DEPRECATED
+guint16  gtk_color_selection_get_previous_alpha  (GtkColorSelection *colorsel);
+
+GDK_DEPRECATED_FOR(gtk_color_chooser_set_rgba)
+void     gtk_color_selection_set_current_rgba    (GtkColorSelection *colorsel,
+                                                  const GdkRGBA     *rgba);
+GDK_DEPRECATED_FOR(gtk_color_chooser_get_rgba)
+void     gtk_color_selection_get_current_rgba    (GtkColorSelection *colorsel,
+                                                  GdkRGBA           *rgba);
+GDK_DEPRECATED
+void     gtk_color_selection_set_previous_rgba   (GtkColorSelection *colorsel,
+                                                  const GdkRGBA     *rgba);
+GDK_DEPRECATED
+void     gtk_color_selection_get_previous_rgba   (GtkColorSelection *colorsel,
+                                                  GdkRGBA           *rgba);
+
+GDK_DEPRECATED
+gboolean gtk_color_selection_is_adjusting        (GtkColorSelection *colorsel);
+
+GDK_DEPRECATED
+gboolean gtk_color_selection_palette_from_string (const gchar       *str,
+                                                  GdkColor         **colors,
+                                                  gint              *n_colors);
+GDK_DEPRECATED
+gchar*   gtk_color_selection_palette_to_string   (const GdkColor    *colors,
+                                                  gint               n_colors);
+
+GtkColorSelectionChangePaletteWithScreenFunc gtk_color_selection_set_change_palette_with_screen_hook (GtkColorSelectionChangePaletteWithScreenFunc func);
+
+GDK_DEPRECATED_FOR(gtk_color_chooser_set_rgba)
+void     gtk_color_selection_set_current_color   (GtkColorSelection *colorsel,
+                                                  const GdkColor    *color);
+GDK_DEPRECATED_FOR(gtk_color_chooser_get_rgba)
+void     gtk_color_selection_get_current_color   (GtkColorSelection *colorsel,
+                                                  GdkColor          *color);
+GDK_DEPRECATED
+void     gtk_color_selection_set_previous_color  (GtkColorSelection *colorsel,
+                                                  const GdkColor    *color);
+GDK_DEPRECATED
+void     gtk_color_selection_get_previous_color  (GtkColorSelection *colorsel,
+                                                  GdkColor          *color);
+
+
+G_END_DECLS
+
+#endif /* __GTK_COLOR_SELECTION_H__ */
diff --git a/gtk/deprecated/gtkcolorseldialog.c b/gtk/deprecated/gtkcolorseldialog.c
new file mode 100644 (file)
index 0000000..772a8cb
--- /dev/null
@@ -0,0 +1,290 @@
+/* GTK - The GIMP Toolkit
+ * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+/*
+ * Modified by the GTK+ Team and others 1997-2000.  See the AUTHORS
+ * file for a list of people on the GTK+ Team.  See the ChangeLog
+ * files for a list of changes.  These files are distributed with
+ * GTK+ at ftp://ftp.gtk.org/pub/gtk/. 
+ */
+#include "config.h"
+
+#define GDK_DISABLE_DEPRECATION_WARNINGS
+
+
+#include <string.h>
+#include <glib.h>
+#include "gtkcolorseldialog.h"
+#include "gtkframe.h"
+#include "gtkbutton.h"
+#include "gtkstock.h"
+#include "gtkintl.h"
+#include "gtkbuildable.h"
+
+
+/**
+ * SECTION:gtkcolorseldlg
+ * @Short_description: Deprecated dialog box for selecting a color
+ * @Title: GtkColorSelectionDialog
+ *
+ * The #GtkColorSelectionDialog provides a standard dialog which
+ * allows the user to select a color much like the #GtkFileSelection
+ * provides a standard dialog for file selection.
+ *
+ * Use gtk_color_selection_dialog_get_color_selection() to get the
+ * #GtkColorSelection widget contained within the dialog. Use this widget
+ * and its gtk_color_selection_get_current_color()
+ * function to gain access to the selected color.  Connect a handler
+ * for this widget's #GtkColorSelection::color-changed signal to be notified
+ * when the color changes.
+ *
+ * <refsect2 id="GtkColorSelectionDialog-BUILDER-UI">
+ * <title>GtkColorSelectionDialog as GtkBuildable</title>
+ * The GtkColorSelectionDialog implementation of the GtkBuildable interface
+ * exposes the embedded #GtkColorSelection as internal child with the
+ * name "color_selection". It also exposes the buttons with the names
+ * "ok_button", "cancel_button" and "help_button".
+ * </refsect2>
+ */
+
+
+struct _GtkColorSelectionDialogPrivate
+{
+  GtkWidget *colorsel;
+  GtkWidget *ok_button;
+  GtkWidget *cancel_button;
+  GtkWidget *help_button;
+};
+
+enum {
+  PROP_0,
+  PROP_COLOR_SELECTION,
+  PROP_OK_BUTTON,
+  PROP_CANCEL_BUTTON,
+  PROP_HELP_BUTTON
+};
+
+
+/***************************/
+/* GtkColorSelectionDialog */
+/***************************/
+
+static void gtk_color_selection_dialog_buildable_interface_init     (GtkBuildableIface *iface);
+static GObject * gtk_color_selection_dialog_buildable_get_internal_child (GtkBuildable *buildable,
+                                                                         GtkBuilder   *builder,
+                                                                         const gchar  *childname);
+
+G_DEFINE_TYPE_WITH_CODE (GtkColorSelectionDialog, gtk_color_selection_dialog,
+           GTK_TYPE_DIALOG,
+           G_IMPLEMENT_INTERFACE (GTK_TYPE_BUILDABLE,
+                      gtk_color_selection_dialog_buildable_interface_init))
+
+static GtkBuildableIface *parent_buildable_iface;
+
+static void
+gtk_color_selection_dialog_get_property (GObject         *object,
+                                        guint            prop_id,
+                                        GValue          *value,
+                                        GParamSpec      *pspec)
+{
+  GtkColorSelectionDialog *colorsel = GTK_COLOR_SELECTION_DIALOG (object);
+  GtkColorSelectionDialogPrivate *priv = colorsel->priv;
+
+  switch (prop_id)
+    {
+    case PROP_COLOR_SELECTION:
+      g_value_set_object (value, priv->colorsel);
+      break;
+    case PROP_OK_BUTTON:
+      g_value_set_object (value, priv->ok_button);
+      break;
+    case PROP_CANCEL_BUTTON:
+      g_value_set_object (value, priv->cancel_button);
+      break;
+    case PROP_HELP_BUTTON:
+      g_value_set_object (value, priv->help_button);
+      break;
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+      break;
+    }
+}
+
+static void
+gtk_color_selection_dialog_class_init (GtkColorSelectionDialogClass *klass)
+{
+  GObjectClass   *gobject_class = G_OBJECT_CLASS (klass);
+  GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
+
+  gobject_class->get_property = gtk_color_selection_dialog_get_property;
+
+  g_object_class_install_property (gobject_class,
+                                  PROP_COLOR_SELECTION,
+                                  g_param_spec_object ("color-selection",
+                                                    P_("Color Selection"),
+                                                    P_("The color selection embedded in the dialog."),
+                                                    GTK_TYPE_WIDGET,
+                                                    G_PARAM_READABLE));
+  g_object_class_install_property (gobject_class,
+                                  PROP_OK_BUTTON,
+                                  g_param_spec_object ("ok-button",
+                                                    P_("OK Button"),
+                                                    P_("The OK button of the dialog."),
+                                                    GTK_TYPE_WIDGET,
+                                                    G_PARAM_READABLE));
+  g_object_class_install_property (gobject_class,
+                                  PROP_CANCEL_BUTTON,
+                                  g_param_spec_object ("cancel-button",
+                                                    P_("Cancel Button"),
+                                                    P_("The cancel button of the dialog."),
+                                                    GTK_TYPE_WIDGET,
+                                                    G_PARAM_READABLE));
+  g_object_class_install_property (gobject_class,
+                                  PROP_HELP_BUTTON,
+                                  g_param_spec_object ("help-button",
+                                                    P_("Help Button"),
+                                                    P_("The help button of the dialog."),
+                                                    GTK_TYPE_WIDGET,
+                                                    G_PARAM_READABLE));
+
+  gtk_widget_class_set_accessible_role (widget_class, ATK_ROLE_COLOR_CHOOSER);
+
+  g_type_class_add_private (klass, sizeof (GtkColorSelectionDialogPrivate));
+}
+
+static void
+gtk_color_selection_dialog_init (GtkColorSelectionDialog *colorseldiag)
+{
+  GtkColorSelectionDialogPrivate *priv;
+  GtkDialog *dialog = GTK_DIALOG (colorseldiag);
+  GtkWidget *action_area, *content_area;
+
+  colorseldiag->priv = G_TYPE_INSTANCE_GET_PRIVATE (colorseldiag,
+                                                    GTK_TYPE_COLOR_SELECTION_DIALOG,
+                                                    GtkColorSelectionDialogPrivate);
+  priv = colorseldiag->priv;
+
+  content_area = gtk_dialog_get_content_area (dialog);
+  action_area = gtk_dialog_get_action_area (dialog);
+
+  gtk_container_set_border_width (GTK_CONTAINER (dialog), 5);
+  gtk_box_set_spacing (GTK_BOX (content_area), 2); /* 2 * 5 + 2 = 12 */
+  gtk_container_set_border_width (GTK_CONTAINER (action_area), 5);
+  gtk_box_set_spacing (GTK_BOX (action_area), 6);
+
+  priv->colorsel = gtk_color_selection_new ();
+  gtk_container_set_border_width (GTK_CONTAINER (priv->colorsel), 5);
+  gtk_color_selection_set_has_palette (GTK_COLOR_SELECTION (priv->colorsel), FALSE);
+  gtk_color_selection_set_has_opacity_control (GTK_COLOR_SELECTION (priv->colorsel), FALSE);
+  gtk_container_add (GTK_CONTAINER (content_area), priv->colorsel);
+  gtk_widget_show (priv->colorsel);
+
+  priv->cancel_button = gtk_dialog_add_button (dialog,
+                                               GTK_STOCK_CANCEL,
+                                               GTK_RESPONSE_CANCEL);
+
+  priv->ok_button = gtk_dialog_add_button (dialog,
+                                           _("_Select"),
+                                           GTK_RESPONSE_OK);
+
+  gtk_widget_grab_default (priv->ok_button);
+
+  priv->help_button = gtk_dialog_add_button (dialog,
+                                             GTK_STOCK_HELP,
+                                             GTK_RESPONSE_HELP);
+
+  gtk_widget_hide (priv->help_button);
+
+  gtk_dialog_set_alternative_button_order (dialog,
+                                          GTK_RESPONSE_OK,
+                                          GTK_RESPONSE_CANCEL,
+                                          GTK_RESPONSE_HELP,
+                                          -1);
+
+  gtk_window_set_title (GTK_WINDOW (colorseldiag),
+                        _("Color Selection"));
+}
+
+/**
+ * gtk_color_selection_dialog_new:
+ * @title: a string containing the title text for the dialog.
+ *
+ * Creates a new #GtkColorSelectionDialog.
+ *
+ * Returns: a #GtkColorSelectionDialog.
+ */
+GtkWidget*
+gtk_color_selection_dialog_new (const gchar *title)
+{
+  GtkColorSelectionDialog *colorseldiag;
+  
+  colorseldiag = g_object_new (GTK_TYPE_COLOR_SELECTION_DIALOG, NULL);
+
+  if (title)
+    gtk_window_set_title (GTK_WINDOW (colorseldiag), title);
+
+  gtk_window_set_resizable (GTK_WINDOW (colorseldiag), FALSE);
+  
+  return GTK_WIDGET (colorseldiag);
+}
+
+/**
+ * gtk_color_selection_dialog_get_color_selection:
+ * @colorsel: a #GtkColorSelectionDialog
+ *
+ * Retrieves the #GtkColorSelection widget embedded in the dialog.
+ *
+ * Returns: (transfer none): the embedded #GtkColorSelection
+ *
+ * Since: 2.14
+ **/
+GtkWidget*
+gtk_color_selection_dialog_get_color_selection (GtkColorSelectionDialog *colorsel)
+{
+  g_return_val_if_fail (GTK_IS_COLOR_SELECTION_DIALOG (colorsel), NULL);
+
+  return colorsel->priv->colorsel;
+}
+
+static void
+gtk_color_selection_dialog_buildable_interface_init (GtkBuildableIface *iface)
+{
+  parent_buildable_iface = g_type_interface_peek_parent (iface);
+  iface->get_internal_child = gtk_color_selection_dialog_buildable_get_internal_child;
+}
+
+static GObject *
+gtk_color_selection_dialog_buildable_get_internal_child (GtkBuildable *buildable,
+                                                        GtkBuilder   *builder,
+                                                        const gchar  *childname)
+{
+  GtkColorSelectionDialog *selection_dialog = GTK_COLOR_SELECTION_DIALOG (buildable);
+  GtkColorSelectionDialogPrivate *priv = selection_dialog->priv;
+
+  if (g_strcmp0 (childname, "ok_button") == 0)
+    return G_OBJECT (priv->ok_button);
+  else if (g_strcmp0 (childname, "cancel_button") == 0)
+    return G_OBJECT (priv->cancel_button);
+  else if (g_strcmp0 (childname, "help_button") == 0)
+    return G_OBJECT (priv->help_button);
+  else if (g_strcmp0 (childname, "color_selection") == 0)
+    return G_OBJECT (priv->colorsel);
+
+  return parent_buildable_iface->get_internal_child (buildable, builder, childname);
+}
diff --git a/gtk/deprecated/gtkcolorseldialog.h b/gtk/deprecated/gtkcolorseldialog.h
new file mode 100644 (file)
index 0000000..a989fc2
--- /dev/null
@@ -0,0 +1,82 @@
+/* GTK - The GIMP Toolkit
+ * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+/*
+ * Modified by the GTK+ Team and others 1997-2000.  See the AUTHORS
+ * file for a list of people on the GTK+ Team.  See the ChangeLog
+ * files for a list of changes.  These files are distributed with
+ * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
+ */
+
+#if !defined (__GTK_H_INSIDE__) && !defined (GTK_COMPILATION)
+#error "Only <gtk/gtk.h> can be included directly."
+#endif
+
+#ifndef __GTK_COLOR_SELECTION_DIALOG_H__
+#define __GTK_COLOR_SELECTION_DIALOG_H__
+
+#include <gtk/gtkdialog.h>
+#include <gtk/deprecated/gtkcolorsel.h>
+
+G_BEGIN_DECLS
+
+#define GTK_TYPE_COLOR_SELECTION_DIALOG            (gtk_color_selection_dialog_get_type ())
+#define GTK_COLOR_SELECTION_DIALOG(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_COLOR_SELECTION_DIALOG, GtkColorSelectionDialog))
+#define GTK_COLOR_SELECTION_DIALOG_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_COLOR_SELECTION_DIALOG, GtkColorSelectionDialogClass))
+#define GTK_IS_COLOR_SELECTION_DIALOG(obj)         (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_COLOR_SELECTION_DIALOG))
+#define GTK_IS_COLOR_SELECTION_DIALOG_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_COLOR_SELECTION_DIALOG))
+#define GTK_COLOR_SELECTION_DIALOG_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_COLOR_SELECTION_DIALOG, GtkColorSelectionDialogClass))
+
+
+typedef struct _GtkColorSelectionDialog              GtkColorSelectionDialog;
+typedef struct _GtkColorSelectionDialogPrivate       GtkColorSelectionDialogPrivate;
+typedef struct _GtkColorSelectionDialogClass         GtkColorSelectionDialogClass;
+
+
+struct _GtkColorSelectionDialog
+{
+  GtkDialog parent_instance;
+
+  /*< private >*/
+  GtkColorSelectionDialogPrivate *priv;
+};
+
+struct _GtkColorSelectionDialogClass
+{
+  GtkDialogClass parent_class;
+
+  /* Padding for future expansion */
+  void (*_gtk_reserved1) (void);
+  void (*_gtk_reserved2) (void);
+  void (*_gtk_reserved3) (void);
+  void (*_gtk_reserved4) (void);
+};
+
+
+/* ColorSelectionDialog */
+GType      gtk_color_selection_dialog_get_type            (void) G_GNUC_CONST;
+GDK_DEPRECATED_FOR(gtk_color_chooser_dialog_new)
+GtkWidget* gtk_color_selection_dialog_new                 (const gchar *title);
+GDK_DEPRECATED_FOR(GtkColorChooser)
+GtkWidget* gtk_color_selection_dialog_get_color_selection (GtkColorSelectionDialog *colorsel);
+
+
+G_END_DECLS
+
+#endif /* __GTK_COLOR_SELECTION_DIALOG_H__ */
diff --git a/gtk/deprecated/gtkhsv.c b/gtk/deprecated/gtkhsv.c
new file mode 100644 (file)
index 0000000..3fac2e1
--- /dev/null
@@ -0,0 +1,1537 @@
+/* HSV color selector for GTK+
+ *
+ * Copyright (C) 1999 The Free Software Foundation
+ *
+ * Authors: Simon Budig <Simon.Budig@unix-ag.org> (original code)
+ *          Federico Mena-Quintero <federico@gimp.org> (cleanup for GTK+)
+ *          Jonathan Blandford <jrb@redhat.com> (cleanup for GTK+)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+/*
+ * Modified by the GTK+ Team and others 1997-2000.  See the AUTHORS
+ * file for a list of people on the GTK+ Team.  See the ChangeLog
+ * files for a list of changes.  These files are distributed with
+ * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
+ */
+
+#include "config.h"
+
+#define GDK_DISABLE_DEPRECATION_WARNINGS
+
+#include <math.h>
+#include <string.h>
+
+#include "gtkhsv.h"
+#include "gtkbindings.h"
+#include "gtkmarshalers.h"
+#include "gtktypebuiltins.h"
+#include "gtkintl.h"
+
+
+/**
+ * SECTION:gtkhsv
+ * @Short_description: A 'color wheel' widget
+ * @Title: GtkHSV
+ * @See_also: #GtkColorSelection, #GtkColorSelectionDialog
+ *
+ * #GtkHSV is the 'color wheel' part of a complete color selector widget.
+ * It allows to select a color by determining its HSV components in an
+ * intuitive way. Moving the selection around the outer ring changes the hue,
+ * and moving the selection point inside the inner triangle changes value and
+ * saturation.
+ *
+ * #GtkHSV has been deprecated together with #GtkColorSelection, where
+ * it was used.
+ */
+
+
+/* Default width/height */
+#define DEFAULT_SIZE 100
+
+/* Default ring width */
+#define DEFAULT_RING_WIDTH 10
+
+
+/* Dragging modes */
+typedef enum {
+  DRAG_NONE,
+  DRAG_H,
+  DRAG_SV
+} DragMode;
+
+/* Private part of the GtkHSV structure */
+struct _GtkHSVPrivate
+{
+  /* Color value */
+  double h;
+  double s;
+  double v;
+  
+  /* Size and ring width */
+  int size;
+  int ring_width;
+  
+  /* Window for capturing events */
+  GdkWindow *window;
+  
+  /* Dragging mode */
+  DragMode mode;
+
+  guint focus_on_ring : 1;
+};
+
+
+/* Signal IDs */
+
+enum {
+  CHANGED,
+  MOVE,
+  LAST_SIGNAL
+};
+
+static void     gtk_hsv_destroy              (GtkWidget          *widget);
+static void     gtk_hsv_realize              (GtkWidget          *widget);
+static void     gtk_hsv_unrealize            (GtkWidget          *widget);
+static void     gtk_hsv_get_preferred_width  (GtkWidget          *widget,
+                                              gint               *minimum,
+                                              gint               *natural);
+static void     gtk_hsv_get_preferred_height (GtkWidget          *widget,
+                                              gint               *minimum,
+                                              gint               *natural);
+static void     gtk_hsv_size_allocate        (GtkWidget          *widget,
+                                              GtkAllocation      *allocation);
+static gboolean gtk_hsv_button_press         (GtkWidget          *widget,
+                                              GdkEventButton     *event);
+static gboolean gtk_hsv_button_release       (GtkWidget          *widget,
+                                              GdkEventButton     *event);
+static gboolean gtk_hsv_motion               (GtkWidget          *widget,
+                                              GdkEventMotion     *event);
+static gboolean gtk_hsv_draw                 (GtkWidget          *widget,
+                                              cairo_t            *cr);
+static gboolean gtk_hsv_grab_broken          (GtkWidget          *widget,
+                                              GdkEventGrabBroken *event);
+static gboolean gtk_hsv_focus                (GtkWidget          *widget,
+                                              GtkDirectionType    direction);
+static void     gtk_hsv_move                 (GtkHSV             *hsv,
+                                              GtkDirectionType    dir);
+
+static guint hsv_signals[LAST_SIGNAL];
+
+G_DEFINE_TYPE (GtkHSV, gtk_hsv, GTK_TYPE_WIDGET)
+
+/* Class initialization function for the HSV color selector */
+static void
+gtk_hsv_class_init (GtkHSVClass *class)
+{
+  GObjectClass   *gobject_class;
+  GtkWidgetClass *widget_class;
+  GtkHSVClass    *hsv_class;
+  GtkBindingSet  *binding_set;
+
+  gobject_class = (GObjectClass *) class;
+  widget_class = (GtkWidgetClass *) class;
+  hsv_class = GTK_HSV_CLASS (class);
+
+  widget_class->destroy = gtk_hsv_destroy;
+  widget_class->realize = gtk_hsv_realize;
+  widget_class->unrealize = gtk_hsv_unrealize;
+  widget_class->get_preferred_width = gtk_hsv_get_preferred_width;
+  widget_class->get_preferred_height = gtk_hsv_get_preferred_height;
+  widget_class->size_allocate = gtk_hsv_size_allocate;
+  widget_class->button_press_event = gtk_hsv_button_press;
+  widget_class->button_release_event = gtk_hsv_button_release;
+  widget_class->motion_notify_event = gtk_hsv_motion;
+  widget_class->draw = gtk_hsv_draw;
+  widget_class->focus = gtk_hsv_focus;
+  widget_class->grab_broken_event = gtk_hsv_grab_broken;
+
+  gtk_widget_class_set_accessible_role (widget_class, ATK_ROLE_COLOR_CHOOSER);
+
+  hsv_class->move = gtk_hsv_move;
+
+  hsv_signals[CHANGED] =
+    g_signal_new (I_("changed"),
+                  G_OBJECT_CLASS_TYPE (gobject_class),
+                  G_SIGNAL_RUN_FIRST,
+                  G_STRUCT_OFFSET (GtkHSVClass, changed),
+                  NULL, NULL,
+                  _gtk_marshal_VOID__VOID,
+                  G_TYPE_NONE, 0);
+
+  hsv_signals[MOVE] =
+    g_signal_new (I_("move"),
+                  G_OBJECT_CLASS_TYPE (gobject_class),
+                  G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
+                  G_STRUCT_OFFSET (GtkHSVClass, move),
+                  NULL, NULL,
+                  _gtk_marshal_VOID__ENUM,
+                  G_TYPE_NONE, 1,
+                  GTK_TYPE_DIRECTION_TYPE);
+
+  binding_set = gtk_binding_set_by_class (class);
+
+  gtk_binding_entry_add_signal (binding_set, GDK_KEY_Up, 0,
+                                "move", 1,
+                                G_TYPE_ENUM, GTK_DIR_UP);
+  gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Up, 0,
+                                "move", 1,
+                                G_TYPE_ENUM, GTK_DIR_UP);
+  gtk_binding_entry_add_signal (binding_set, GDK_KEY_Down, 0,
+                                "move", 1,
+                                G_TYPE_ENUM, GTK_DIR_DOWN);
+  gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Down, 0,
+                                "move", 1,
+                                G_TYPE_ENUM, GTK_DIR_DOWN);
+  gtk_binding_entry_add_signal (binding_set, GDK_KEY_Right, 0,
+                                "move", 1,
+                                G_TYPE_ENUM, GTK_DIR_RIGHT);
+  gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Right, 0,
+                                "move", 1,
+                                G_TYPE_ENUM, GTK_DIR_RIGHT);
+  gtk_binding_entry_add_signal (binding_set, GDK_KEY_Left, 0,
+                                "move", 1,
+                                G_TYPE_ENUM, GTK_DIR_LEFT);
+  gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Left, 0,
+                                "move", 1,
+                                G_TYPE_ENUM, GTK_DIR_LEFT);
+
+  g_type_class_add_private (gobject_class, sizeof (GtkHSVPrivate));
+}
+
+static void
+gtk_hsv_init (GtkHSV *hsv)
+{
+  GtkHSVPrivate *priv;
+
+  priv = G_TYPE_INSTANCE_GET_PRIVATE (hsv, GTK_TYPE_HSV, GtkHSVPrivate);
+
+  hsv->priv = priv;
+
+  gtk_widget_set_has_window (GTK_WIDGET (hsv), FALSE);
+  gtk_widget_set_can_focus (GTK_WIDGET (hsv), TRUE);
+
+  priv->h = 0.0;
+  priv->s = 0.0;
+  priv->v = 0.0;
+
+  priv->size = DEFAULT_SIZE;
+  priv->ring_width = DEFAULT_RING_WIDTH;
+}
+
+static void
+gtk_hsv_destroy (GtkWidget *widget)
+{
+  GTK_WIDGET_CLASS (gtk_hsv_parent_class)->destroy (widget);
+}
+
+static void
+gtk_hsv_realize (GtkWidget *widget)
+{
+  GtkHSV *hsv = GTK_HSV (widget);
+  GtkHSVPrivate *priv = hsv->priv;
+  GtkAllocation allocation;
+  GdkWindow *parent_window;
+  GdkWindowAttr attr;
+  int attr_mask;
+
+  gtk_widget_set_realized (widget, TRUE);
+
+  gtk_widget_get_allocation (widget, &allocation);
+
+  attr.window_type = GDK_WINDOW_CHILD;
+  attr.x = allocation.x;
+  attr.y = allocation.y;
+  attr.width = allocation.width;
+  attr.height = allocation.height;
+  attr.wclass = GDK_INPUT_ONLY;
+  attr.event_mask = gtk_widget_get_events (widget);
+  attr.event_mask |= (GDK_KEY_PRESS_MASK
+                      | GDK_BUTTON_PRESS_MASK
+                      | GDK_BUTTON_RELEASE_MASK
+                      | GDK_POINTER_MOTION_MASK
+                      | GDK_ENTER_NOTIFY_MASK
+                      | GDK_LEAVE_NOTIFY_MASK);
+  attr_mask = GDK_WA_X | GDK_WA_Y;
+
+  parent_window = gtk_widget_get_parent_window (widget);
+  gtk_widget_set_window (widget, parent_window);
+  g_object_ref (parent_window);
+
+  priv->window = gdk_window_new (parent_window, &attr, attr_mask);
+  gdk_window_set_user_data (priv->window, hsv);
+  gdk_window_show (priv->window);
+}
+
+static void
+gtk_hsv_unrealize (GtkWidget *widget)
+{
+  GtkHSV *hsv = GTK_HSV (widget);
+  GtkHSVPrivate *priv = hsv->priv;
+
+  gdk_window_set_user_data (priv->window, NULL);
+  gdk_window_destroy (priv->window);
+  priv->window = NULL;
+
+  GTK_WIDGET_CLASS (gtk_hsv_parent_class)->unrealize (widget);
+}
+
+static void
+gtk_hsv_get_preferred_width (GtkWidget *widget,
+                             gint      *minimum,
+                             gint      *natural)
+{
+  GtkHSV *hsv = GTK_HSV (widget);
+  GtkHSVPrivate *priv = hsv->priv;
+  gint focus_width;
+  gint focus_pad;
+
+  gtk_widget_style_get (widget,
+                        "focus-line-width", &focus_width,
+                        "focus-padding", &focus_pad,
+                        NULL);
+
+  *minimum = priv->size + 2 * (focus_width + focus_pad);
+  *natural = priv->size + 2 * (focus_width + focus_pad);
+}
+
+static void
+gtk_hsv_get_preferred_height (GtkWidget *widget,
+                              gint      *minimum,
+                              gint      *natural)
+{
+  GtkHSV *hsv = GTK_HSV (widget);
+  GtkHSVPrivate *priv = hsv->priv;
+  gint focus_width;
+  gint focus_pad;
+
+  gtk_widget_style_get (widget,
+                        "focus-line-width", &focus_width,
+                        "focus-padding", &focus_pad,
+                        NULL);
+
+  *minimum = priv->size + 2 * (focus_width + focus_pad);
+  *natural = priv->size + 2 * (focus_width + focus_pad);
+}
+
+static void
+gtk_hsv_size_allocate (GtkWidget     *widget,
+                       GtkAllocation *allocation)
+{
+  GtkHSV *hsv = GTK_HSV (widget);
+  GtkHSVPrivate *priv = hsv->priv;
+
+  gtk_widget_set_allocation (widget, allocation);
+
+  if (gtk_widget_get_realized (widget))
+    gdk_window_move_resize (priv->window,
+                            allocation->x,
+                            allocation->y,
+                            allocation->width,
+                            allocation->height);
+}
+
+
+/* Utility functions */
+
+#define INTENSITY(r, g, b) ((r) * 0.30 + (g) * 0.59 + (b) * 0.11)
+
+/* Converts from HSV to RGB */
+static void
+hsv_to_rgb (gdouble *h,
+            gdouble *s,
+            gdouble *v)
+{
+  gdouble hue, saturation, value;
+  gdouble f, p, q, t;
+
+  if (*s == 0.0)
+    {
+      *h = *v;
+      *s = *v;
+      *v = *v; /* heh */
+    }
+  else
+    {
+      hue = *h * 6.0;
+      saturation = *s;
+      value = *v;
+
+      if (hue == 6.0)
+        hue = 0.0;
+
+      f = hue - (int) hue;
+      p = value * (1.0 - saturation);
+      q = value * (1.0 - saturation * f);
+      t = value * (1.0 - saturation * (1.0 - f));
+
+      switch ((int) hue)
+        {
+        case 0:
+          *h = value;
+          *s = t;
+          *v = p;
+          break;
+
+        case 1:
+          *h = q;
+          *s = value;
+          *v = p;
+          break;
+
+        case 2:
+          *h = p;
+          *s = value;
+          *v = t;
+          break;
+
+        case 3:
+          *h = p;
+          *s = q;
+          *v = value;
+          break;
+
+        case 4:
+          *h = t;
+          *s = p;
+          *v = value;
+          break;
+
+        case 5:
+          *h = value;
+          *s = p;
+          *v = q;
+          break;
+
+        default:
+          g_assert_not_reached ();
+        }
+    }
+}
+
+/* Converts from RGB to HSV */
+static void
+rgb_to_hsv (gdouble *r,
+            gdouble *g,
+            gdouble *b)
+{
+  gdouble red, green, blue;
+  gdouble h, s, v;
+  gdouble min, max;
+  gdouble delta;
+
+  red = *r;
+  green = *g;
+  blue = *b;
+
+  h = 0.0;
+
+  if (red > green)
+    {
+      if (red > blue)
+        max = red;
+      else
+        max = blue;
+
+      if (green < blue)
+        min = green;
+      else
+        min = blue;
+    }
+  else
+    {
+      if (green > blue)
+        max = green;
+      else
+        max = blue;
+
+      if (red < blue)
+        min = red;
+      else
+        min = blue;
+    }
+
+  v = max;
+
+  if (max != 0.0)
+    s = (max - min) / max;
+  else
+    s = 0.0;
+
+  if (s == 0.0)
+    h = 0.0;
+  else
+    {
+      delta = max - min;
+
+      if (red == max)
+        h = (green - blue) / delta;
+      else if (green == max)
+        h = 2 + (blue - red) / delta;
+      else if (blue == max)
+        h = 4 + (red - green) / delta;
+
+      h /= 6.0;
+
+      if (h < 0.0)
+        h += 1.0;
+      else if (h > 1.0)
+        h -= 1.0;
+    }
+
+  *r = h;
+  *g = s;
+  *b = v;
+}
+
+/* Computes the vertices of the saturation/value triangle */
+static void
+compute_triangle (GtkHSV *hsv,
+                  gint   *hx,
+                  gint   *hy,
+                  gint   *sx,
+                  gint   *sy,
+                  gint   *vx,
+                  gint   *vy)
+{
+  GtkHSVPrivate *priv = hsv->priv;
+  GtkWidget *widget = GTK_WIDGET (hsv);
+  gdouble center_x;
+  gdouble center_y;
+  gdouble inner, outer;
+  gdouble angle;
+
+  center_x = gtk_widget_get_allocated_width (widget) / 2.0;
+  center_y = gtk_widget_get_allocated_height (widget) / 2.0;
+  outer = priv->size / 2.0;
+  inner = outer - priv->ring_width;
+  angle = priv->h * 2.0 * G_PI;
+
+  *hx = floor (center_x + cos (angle) * inner + 0.5);
+  *hy = floor (center_y - sin (angle) * inner + 0.5);
+  *sx = floor (center_x + cos (angle + 2.0 * G_PI / 3.0) * inner + 0.5);
+  *sy = floor (center_y - sin (angle + 2.0 * G_PI / 3.0) * inner + 0.5);
+  *vx = floor (center_x + cos (angle + 4.0 * G_PI / 3.0) * inner + 0.5);
+  *vy = floor (center_y - sin (angle + 4.0 * G_PI / 3.0) * inner + 0.5);
+}
+
+/* Computes whether a point is inside the hue ring */
+static gboolean
+is_in_ring (GtkHSV *hsv,
+            gdouble x,
+            gdouble y)
+{
+  GtkHSVPrivate *priv = hsv->priv;
+  GtkWidget *widget = GTK_WIDGET (hsv);
+  gdouble dx, dy, dist;
+  gdouble center_x;
+  gdouble center_y;
+  gdouble inner, outer;
+
+  center_x = gtk_widget_get_allocated_width (widget) / 2.0;
+  center_y = gtk_widget_get_allocated_height (widget) / 2.0;
+  outer = priv->size / 2.0;
+  inner = outer - priv->ring_width;
+
+  dx = x - center_x;
+  dy = center_y - y;
+  dist = dx * dx + dy * dy;
+
+  return (dist >= inner * inner && dist <= outer * outer);
+}
+
+/* Computes a saturation/value pair based on the mouse coordinates */
+static void
+compute_sv (GtkHSV  *hsv,
+            gdouble  x,
+            gdouble  y,
+            gdouble *s,
+            gdouble *v)
+{
+  GtkWidget *widget = GTK_WIDGET (hsv);
+  int ihx, ihy, isx, isy, ivx, ivy;
+  double hx, hy, sx, sy, vx, vy;
+  double center_x;
+  double center_y;
+
+  compute_triangle (hsv, &ihx, &ihy, &isx, &isy, &ivx, &ivy);
+  center_x = gtk_widget_get_allocated_width (widget) / 2.0;
+  center_y = gtk_widget_get_allocated_height (widget) / 2.0;
+  hx = ihx - center_x;
+  hy = center_y - ihy;
+  sx = isx - center_x;
+  sy = center_y - isy;
+  vx = ivx - center_x;
+  vy = center_y - ivy;
+  x -= center_x;
+  y = center_y - y;
+  
+  if (vx * (x - sx) + vy * (y - sy) < 0.0)
+    {
+      *s = 1.0;
+      *v = (((x - sx) * (hx - sx) + (y - sy) * (hy-sy))
+            / ((hx - sx) * (hx - sx) + (hy - sy) * (hy - sy)));
+      
+      if (*v < 0.0)
+        *v = 0.0;
+      else if (*v > 1.0)
+        *v = 1.0;
+    }
+  else if (hx * (x - sx) + hy * (y - sy) < 0.0)
+    {
+      *s = 0.0;
+      *v = (((x - sx) * (vx - sx) + (y - sy) * (vy - sy))
+            / ((vx - sx) * (vx - sx) + (vy - sy) * (vy - sy)));
+      
+      if (*v < 0.0)
+        *v = 0.0;
+      else if (*v > 1.0)
+        *v = 1.0;
+    }
+  else if (sx * (x - hx) + sy * (y - hy) < 0.0)
+    {
+      *v = 1.0;
+      *s = (((x - vx) * (hx - vx) + (y - vy) * (hy - vy)) /
+            ((hx - vx) * (hx - vx) + (hy - vy) * (hy - vy)));
+      
+      if (*s < 0.0)
+        *s = 0.0;
+      else if (*s > 1.0)
+        *s = 1.0;
+    }
+  else
+    {
+      *v = (((x - sx) * (hy - vy) - (y - sy) * (hx - vx))
+            / ((vx - sx) * (hy - vy) - (vy - sy) * (hx - vx)));
+      
+      if (*v<= 0.0)
+        {
+          *v = 0.0;
+          *s = 0.0;
+        }
+      else
+        {
+          if (*v > 1.0)
+            *v = 1.0;
+
+          if (fabs (hy - vy) < fabs (hx - vx))
+            *s = (x - sx - *v * (vx - sx)) / (*v * (hx - vx));
+          else
+            *s = (y - sy - *v * (vy - sy)) / (*v * (hy - vy));
+
+          if (*s < 0.0)
+            *s = 0.0;
+          else if (*s > 1.0)
+            *s = 1.0;
+        }
+    }
+}
+
+/* Computes whether a point is inside the saturation/value triangle */
+static gboolean
+is_in_triangle (GtkHSV *hsv,
+                gdouble x,
+                gdouble y)
+{
+  int hx, hy, sx, sy, vx, vy;
+  double det, s, v;
+  
+  compute_triangle (hsv, &hx, &hy, &sx, &sy, &vx, &vy);
+  
+  det = (vx - sx) * (hy - sy) - (vy - sy) * (hx - sx);
+  
+  s = ((x - sx) * (hy - sy) - (y - sy) * (hx - sx)) / det;
+  v = ((vx - sx) * (y - sy) - (vy - sy) * (x - sx)) / det;
+  
+  return (s >= 0.0 && v >= 0.0 && s + v <= 1.0);
+}
+
+/* Computes a value based on the mouse coordinates */
+static double
+compute_v (GtkHSV *hsv,
+           gdouble x,
+           gdouble y)
+{
+  GtkWidget *widget = GTK_WIDGET (hsv);
+  double center_x;
+  double center_y;
+  double dx, dy;
+  double angle;
+
+  center_x = gtk_widget_get_allocated_width (widget) / 2.0;
+  center_y = gtk_widget_get_allocated_height (widget) / 2.0;
+  dx = x - center_x;
+  dy = center_y - y;
+
+  angle = atan2 (dy, dx);
+  if (angle < 0.0)
+    angle += 2.0 * G_PI;
+
+  return angle / (2.0 * G_PI);
+}
+
+/* Event handlers */
+
+static void
+set_cross_grab (GtkHSV    *hsv,
+                GdkDevice *device,
+                guint32    time)
+{
+  GtkHSVPrivate *priv = hsv->priv;
+  GdkCursor *cursor;
+
+  cursor = gdk_cursor_new_for_display (gtk_widget_get_display (GTK_WIDGET (hsv)),
+                                       GDK_CROSSHAIR);
+  gdk_device_grab (device,
+                   priv->window,
+                   GDK_OWNERSHIP_NONE,
+                   FALSE,
+                   GDK_POINTER_MOTION_MASK
+                    | GDK_POINTER_MOTION_HINT_MASK
+                    | GDK_BUTTON_RELEASE_MASK,
+                   cursor,
+                   time);
+  g_object_unref (cursor);
+}
+
+static gboolean
+gtk_hsv_grab_broken (GtkWidget          *widget,
+                     GdkEventGrabBroken *event)
+{
+  GtkHSV *hsv = GTK_HSV (widget);
+  GtkHSVPrivate *priv = hsv->priv;
+
+  priv->mode = DRAG_NONE;
+
+  return TRUE;
+}
+
+static gint
+gtk_hsv_button_press (GtkWidget      *widget,
+                      GdkEventButton *event)
+{
+  GtkHSV *hsv = GTK_HSV (widget);
+  GtkHSVPrivate *priv = hsv->priv;
+  double x, y;
+
+  if (priv->mode != DRAG_NONE || event->button != GDK_BUTTON_PRIMARY)
+    return FALSE;
+
+  x = event->x;
+  y = event->y;
+
+  if (is_in_ring (hsv, x, y))
+    {
+      priv->mode = DRAG_H;
+      set_cross_grab (hsv, gdk_event_get_device ((GdkEvent *) event), event->time);
+
+      gtk_hsv_set_color (hsv,
+                         compute_v (hsv, x, y),
+                         priv->s,
+                         priv->v);
+
+      gtk_widget_grab_focus (widget);
+      priv->focus_on_ring = TRUE;
+
+      return TRUE;
+    }
+
+  if (is_in_triangle (hsv, x, y))
+    {
+      gdouble s, v;
+
+      priv->mode = DRAG_SV;
+      set_cross_grab (hsv, gdk_event_get_device ((GdkEvent *) event), event->time);
+
+      compute_sv (hsv, x, y, &s, &v);
+      gtk_hsv_set_color (hsv, priv->h, s, v);
+
+      gtk_widget_grab_focus (widget);
+      priv->focus_on_ring = FALSE;
+
+      return TRUE;
+    }
+
+  return FALSE;
+}
+
+static gint
+gtk_hsv_button_release (GtkWidget      *widget,
+                        GdkEventButton *event)
+{
+  GtkHSV *hsv = GTK_HSV (widget);
+  GtkHSVPrivate *priv = hsv->priv;
+  DragMode mode;
+  gdouble x, y;
+
+  if (priv->mode == DRAG_NONE || event->button != GDK_BUTTON_PRIMARY)
+    return FALSE;
+
+  /* Set the drag mode to DRAG_NONE so that signal handlers for "catched"
+   * can see that this is the final color state.
+   */
+  mode = priv->mode;
+  priv->mode = DRAG_NONE;
+
+  x = event->x;
+  y = event->y;
+
+  if (mode == DRAG_H)
+    {
+      gtk_hsv_set_color (hsv, compute_v (hsv, x, y), priv->s, priv->v);
+    }
+  else if (mode == DRAG_SV)
+    {
+      gdouble s, v;
+
+      compute_sv (hsv, x, y, &s, &v);
+      gtk_hsv_set_color (hsv, priv->h, s, v);
+    }
+  else
+    {
+      g_assert_not_reached ();
+    }
+
+  gdk_device_ungrab (gdk_event_get_device ((GdkEvent *) event), event->time);
+
+  return TRUE;
+}
+
+static gint
+gtk_hsv_motion (GtkWidget      *widget,
+                GdkEventMotion *event)
+{
+  GtkHSV *hsv = GTK_HSV (widget);
+  GtkHSVPrivate *priv = hsv->priv;
+  gdouble x, y;
+
+  if (priv->mode == DRAG_NONE)
+    return FALSE;
+
+  gdk_event_request_motions (event);
+  x = event->x;
+  y = event->y;
+
+  if (priv->mode == DRAG_H)
+    {
+      gtk_hsv_set_color (hsv, compute_v (hsv, x, y), priv->s, priv->v);
+      return TRUE;
+    }
+  else if (priv->mode == DRAG_SV)
+    {
+      gdouble s, v;
+
+      compute_sv (hsv, x, y, &s, &v);
+      gtk_hsv_set_color (hsv, priv->h, s, v);
+      return TRUE;
+    }
+
+  g_assert_not_reached ();
+
+  return FALSE;
+}
+
+
+/* Redrawing */
+
+/* Paints the hue ring */
+static void
+paint_ring (GtkHSV  *hsv,
+            cairo_t *cr)
+{
+  GtkHSVPrivate *priv = hsv->priv;
+  GtkWidget *widget = GTK_WIDGET (hsv);
+  int xx, yy, width, height;
+  gdouble dx, dy, dist;
+  gdouble center_x;
+  gdouble center_y;
+  gdouble inner, outer;
+  guint32 *buf, *p;
+  gdouble angle;
+  gdouble hue;
+  gdouble r, g, b;
+  cairo_surface_t *source;
+  cairo_t *source_cr;
+  gint stride;
+
+  width = gtk_widget_get_allocated_width (widget);
+  height = gtk_widget_get_allocated_height (widget);
+
+  center_x = width / 2.0;
+  center_y = height / 2.0;
+
+  outer = priv->size / 2.0;
+  inner = outer - priv->ring_width;
+
+  /* Create an image initialized with the ring colors */
+
+  stride = cairo_format_stride_for_width (CAIRO_FORMAT_RGB24, width);
+  buf = g_new (guint32, height * stride / 4);
+
+  for (yy = 0; yy < height; yy++)
+    {
+      p = buf + yy * width;
+
+      dy = -(yy - center_y);
+
+      for (xx = 0; xx < width; xx++)
+        {
+          dx = xx - center_x;
+
+          dist = dx * dx + dy * dy;
+          if (dist < ((inner-1) * (inner-1)) || dist > ((outer+1) * (outer+1)))
+            {
+              *p++ = 0;
+              continue;
+            }
+
+          angle = atan2 (dy, dx);
+          if (angle < 0.0)
+            angle += 2.0 * G_PI;
+
+          hue = angle / (2.0 * G_PI);
+
+          r = hue;
+          g = 1.0;
+          b = 1.0;
+          hsv_to_rgb (&r, &g, &b);
+
+          *p++ = (((int)floor (r * 255 + 0.5) << 16) |
+                  ((int)floor (g * 255 + 0.5) << 8) |
+                  (int)floor (b * 255 + 0.5));
+        }
+    }
+
+  source = cairo_image_surface_create_for_data ((unsigned char *)buf,
+                                                CAIRO_FORMAT_RGB24,
+                                                width, height, stride);
+
+  /* Now draw the value marker onto the source image, so that it
+   * will get properly clipped at the edges of the ring
+   */
+  source_cr = cairo_create (source);
+  
+  r = priv->h;
+  g = 1.0;
+  b = 1.0;
+  hsv_to_rgb (&r, &g, &b);
+  
+  if (INTENSITY (r, g, b) > 0.5)
+    cairo_set_source_rgb (source_cr, 0., 0., 0.);
+  else
+    cairo_set_source_rgb (source_cr, 1., 1., 1.);
+
+  cairo_move_to (source_cr, center_x, center_y);
+  cairo_line_to (source_cr,
+                 center_x + cos (priv->h * 2.0 * G_PI) * priv->size / 2,
+                 center_y - sin (priv->h * 2.0 * G_PI) * priv->size / 2);
+  cairo_stroke (source_cr);
+  cairo_destroy (source_cr);
+
+  /* Draw the ring using the source image */
+
+  cairo_save (cr);
+    
+  cairo_set_source_surface (cr, source, 0, 0);
+  cairo_surface_destroy (source);
+
+  cairo_set_line_width (cr, priv->ring_width);
+  cairo_new_path (cr);
+  cairo_arc (cr,
+             center_x, center_y,
+             priv->size / 2. - priv->ring_width / 2.,
+             0, 2 * G_PI);
+  cairo_stroke (cr);
+  
+  cairo_restore (cr);
+  
+  g_free (buf);
+}
+
+/* Converts an HSV triplet to an integer RGB triplet */
+static void
+get_color (gdouble h,
+           gdouble s,
+           gdouble v,
+           gint   *r,
+           gint   *g,
+           gint   *b)
+{
+  hsv_to_rgb (&h, &s, &v);
+  
+  *r = floor (h * 255 + 0.5);
+  *g = floor (s * 255 + 0.5);
+  *b = floor (v * 255 + 0.5);
+}
+
+#define SWAP(a, b, t) ((t) = (a), (a) = (b), (b) = (t))
+
+#define LERP(a, b, v1, v2, i) (((v2) - (v1) != 0)                                       \
+                               ? ((a) + ((b) - (a)) * ((i) - (v1)) / ((v2) - (v1)))     \
+                               : (a))
+
+/* Number of pixels we extend out from the edges when creating
+ * color source to avoid artifacts
+ */
+#define PAD 3
+
+/* Paints the HSV triangle */
+static void
+paint_triangle (GtkHSV   *hsv,
+                cairo_t  *cr,
+                gboolean  draw_focus)
+{
+  GtkHSVPrivate *priv = hsv->priv;
+  GtkWidget *widget = GTK_WIDGET (hsv);
+  gint hx, hy, sx, sy, vx, vy; /* HSV vertices */
+  gint x1, y1, r1, g1, b1; /* First vertex in scanline order */
+  gint x2, y2, r2, g2, b2; /* Second vertex */
+  gint x3, y3, r3, g3, b3; /* Third vertex */
+  gint t;
+  guint32 *buf, *p, c;
+  gint xl, xr, rl, rr, gl, gr, bl, br; /* Scanline data */
+  gint xx, yy;
+  gint x_interp, y_interp;
+  gint x_start, x_end;
+  cairo_surface_t *source;
+  gdouble r, g, b;
+  gint stride;
+  int width, height;
+  GtkStyleContext *context;
+
+  priv = hsv->priv;
+  width = gtk_widget_get_allocated_width (widget); 
+  height = gtk_widget_get_allocated_height (widget); 
+  /* Compute triangle's vertices */
+  
+  compute_triangle (hsv, &hx, &hy, &sx, &sy, &vx, &vy);
+  
+  x1 = hx;
+  y1 = hy;
+  get_color (priv->h, 1.0, 1.0, &r1, &g1, &b1);
+
+  x2 = sx;
+  y2 = sy;
+  get_color (priv->h, 1.0, 0.0, &r2, &g2, &b2);
+
+  x3 = vx;
+  y3 = vy;
+  get_color (priv->h, 0.0, 1.0, &r3, &g3, &b3);
+
+  if (y2 > y3)
+    {
+      SWAP (x2, x3, t);
+      SWAP (y2, y3, t);
+      SWAP (r2, r3, t);
+      SWAP (g2, g3, t);
+      SWAP (b2, b3, t);
+    }
+
+  if (y1 > y3)
+    {
+      SWAP (x1, x3, t);
+      SWAP (y1, y3, t);
+      SWAP (r1, r3, t);
+      SWAP (g1, g3, t);
+      SWAP (b1, b3, t);
+    }
+
+  if (y1 > y2)
+    {
+      SWAP (x1, x2, t);
+      SWAP (y1, y2, t);
+      SWAP (r1, r2, t);
+      SWAP (g1, g2, t);
+      SWAP (b1, b2, t);
+    }
+
+  /* Shade the triangle */
+
+  stride = cairo_format_stride_for_width (CAIRO_FORMAT_RGB24, width);
+  buf = g_new (guint32, height * stride / 4);
+
+  for (yy = 0; yy < height; yy++)
+    {
+      p = buf + yy * width;
+
+      if (yy >= y1 - PAD && yy < y3 + PAD) {
+        y_interp = CLAMP (yy, y1, y3);
+
+        if (y_interp < y2)
+          {
+            xl = LERP (x1, x2, y1, y2, y_interp);
+
+            rl = LERP (r1, r2, y1, y2, y_interp);
+            gl = LERP (g1, g2, y1, y2, y_interp);
+            bl = LERP (b1, b2, y1, y2, y_interp);
+          }
+        else
+          {
+            xl = LERP (x2, x3, y2, y3, y_interp);
+
+            rl = LERP (r2, r3, y2, y3, y_interp);
+            gl = LERP (g2, g3, y2, y3, y_interp);
+            bl = LERP (b2, b3, y2, y3, y_interp);
+          }
+
+        xr = LERP (x1, x3, y1, y3, y_interp);
+
+        rr = LERP (r1, r3, y1, y3, y_interp);
+        gr = LERP (g1, g3, y1, y3, y_interp);
+        br = LERP (b1, b3, y1, y3, y_interp);
+
+        if (xl > xr)
+          {
+            SWAP (xl, xr, t);
+            SWAP (rl, rr, t);
+            SWAP (gl, gr, t);
+            SWAP (bl, br, t);
+          }
+
+        x_start = MAX (xl - PAD, 0);
+        x_end = MIN (xr + PAD, width);
+        x_start = MIN (x_start, x_end);
+
+        c = (rl << 16) | (gl << 8) | bl;
+
+        for (xx = 0; xx < x_start; xx++)
+          *p++ = c;
+
+        for (; xx < x_end; xx++)
+          {
+            x_interp = CLAMP (xx, xl, xr);
+
+            *p++ = ((LERP (rl, rr, xl, xr, x_interp) << 16) |
+                    (LERP (gl, gr, xl, xr, x_interp) << 8) |
+                    LERP (bl, br, xl, xr, x_interp));
+          }
+
+        c = (rr << 16) | (gr << 8) | br;
+
+        for (; xx < width; xx++)
+          *p++ = c;
+      }
+    }
+
+  source = cairo_image_surface_create_for_data ((unsigned char *)buf,
+                                                CAIRO_FORMAT_RGB24,
+                                                width, height, stride);
+  
+  /* Draw a triangle with the image as a source */
+
+  cairo_set_source_surface (cr, source, 0, 0);
+  cairo_surface_destroy (source);
+  
+  cairo_move_to (cr, x1, y1);
+  cairo_line_to (cr, x2, y2);
+  cairo_line_to (cr, x3, y3);
+  cairo_close_path (cr);
+  cairo_fill (cr);
+  
+  g_free (buf);
+  
+  /* Draw value marker */
+  
+  xx = floor (sx + (vx - sx) * priv->v + (hx - vx) * priv->s * priv->v + 0.5);
+  yy = floor (sy + (vy - sy) * priv->v + (hy - vy) * priv->s * priv->v + 0.5);
+  
+  r = priv->h;
+  g = priv->s;
+  b = priv->v;
+  hsv_to_rgb (&r, &g, &b);
+
+  context = gtk_widget_get_style_context (widget);
+
+  gtk_style_context_save (context);
+
+  if (INTENSITY (r, g, b) > 0.5)
+    {
+      gtk_style_context_add_class (context, "light-area-focus");
+      cairo_set_source_rgb (cr, 0., 0., 0.);
+    }
+  else
+    {
+      gtk_style_context_add_class (context, "dark-area-focus");
+      cairo_set_source_rgb (cr, 1., 1., 1.);
+    }
+
+#define RADIUS 4
+#define FOCUS_RADIUS 6
+
+  cairo_new_path (cr);
+  cairo_arc (cr, xx, yy, RADIUS, 0, 2 * G_PI);
+  cairo_stroke (cr);
+  
+  /* Draw focus outline */
+
+  if (draw_focus && !priv->focus_on_ring)
+    {
+      gint focus_width;
+      gint focus_pad;
+
+      gtk_widget_style_get (widget,
+                            "focus-line-width", &focus_width,
+                            "focus-padding", &focus_pad,
+                            NULL);
+
+      gtk_render_focus (context, cr,
+                        xx - FOCUS_RADIUS - focus_width - focus_pad,
+                        yy - FOCUS_RADIUS - focus_width - focus_pad,
+                        2 * (FOCUS_RADIUS + focus_width + focus_pad),
+                        2 * (FOCUS_RADIUS + focus_width + focus_pad));
+    }
+
+  gtk_style_context_restore (context);
+}
+
+/* Paints the contents of the HSV color selector */
+static gboolean
+gtk_hsv_draw (GtkWidget *widget,
+              cairo_t   *cr)
+{
+  GtkHSV *hsv = GTK_HSV (widget);
+  GtkHSVPrivate *priv = hsv->priv;
+  gboolean draw_focus;
+
+  draw_focus = gtk_widget_has_visible_focus (widget);
+
+  paint_ring (hsv, cr);
+  paint_triangle (hsv, cr, draw_focus);
+
+
+  if (draw_focus && priv->focus_on_ring)
+    {
+      GtkStyleContext *context;
+
+      context = gtk_widget_get_style_context (widget);
+
+      gtk_render_focus (context, cr, 0, 0,
+                        gtk_widget_get_allocated_width (widget),
+                        gtk_widget_get_allocated_height (widget));
+    }
+
+  return FALSE;
+}
+
+static gboolean
+gtk_hsv_focus (GtkWidget       *widget,
+               GtkDirectionType dir)
+{
+  GtkHSV *hsv = GTK_HSV (widget);
+  GtkHSVPrivate *priv = hsv->priv;
+
+  if (!gtk_widget_has_focus (widget))
+    {
+      if (dir == GTK_DIR_TAB_BACKWARD)
+        priv->focus_on_ring = FALSE;
+      else
+        priv->focus_on_ring = TRUE;
+
+      gtk_widget_grab_focus (GTK_WIDGET (hsv));
+      return TRUE;
+    }
+  
+  switch (dir)
+    {
+    case GTK_DIR_UP:
+      if (priv->focus_on_ring)
+        return FALSE;
+      else
+        priv->focus_on_ring = TRUE;
+      break;
+
+    case GTK_DIR_DOWN:
+      if (priv->focus_on_ring)
+        priv->focus_on_ring = FALSE;
+      else
+        return FALSE;
+      break;
+
+    case GTK_DIR_LEFT:
+    case GTK_DIR_TAB_BACKWARD:
+      if (priv->focus_on_ring)
+        return FALSE;
+      else
+        priv->focus_on_ring = TRUE;
+      break;
+
+    case GTK_DIR_RIGHT:
+    case GTK_DIR_TAB_FORWARD:
+      if (priv->focus_on_ring)
+        priv->focus_on_ring = FALSE;
+      else
+        return FALSE;
+      break;
+    }
+
+  gtk_widget_queue_draw (GTK_WIDGET (hsv));
+
+  return TRUE;
+}
+
+/**
+ * gtk_hsv_new:
+ *
+ * Creates a new HSV color selector.
+ *
+ * Return value: A newly-created HSV color selector.
+ *
+ * Since: 2.14
+ */
+GtkWidget*
+gtk_hsv_new (void)
+{
+  return g_object_new (GTK_TYPE_HSV, NULL);
+}
+
+/**
+ * gtk_hsv_set_color:
+ * @hsv: An HSV color selector
+ * @h: Hue
+ * @s: Saturation
+ * @v: Value
+ *
+ * Sets the current color in an HSV color selector.
+ * Color component values must be in the [0.0, 1.0] range.
+ *
+ * Since: 2.14
+ */
+void
+gtk_hsv_set_color (GtkHSV *hsv,
+                   gdouble h,
+                   gdouble s,
+                   gdouble v)
+{
+  GtkHSVPrivate *priv;
+
+  g_return_if_fail (GTK_IS_HSV (hsv));
+  g_return_if_fail (h >= 0.0 && h <= 1.0);
+  g_return_if_fail (s >= 0.0 && s <= 1.0);
+  g_return_if_fail (v >= 0.0 && v <= 1.0);
+
+  priv = hsv->priv;
+
+  priv->h = h;
+  priv->s = s;
+  priv->v = v;
+  
+  g_signal_emit (hsv, hsv_signals[CHANGED], 0);
+  
+  gtk_widget_queue_draw (GTK_WIDGET (hsv));
+}
+
+/**
+ * gtk_hsv_get_color:
+ * @hsv: An HSV color selector
+ * @h: (out): Return value for the hue
+ * @s: (out): Return value for the saturation
+ * @v: (out): Return value for the value
+ *
+ * Queries the current color in an HSV color selector.
+ * Returned values will be in the [0.0, 1.0] range.
+ *
+ * Since: 2.14
+ */
+void
+gtk_hsv_get_color (GtkHSV *hsv,
+                   double *h,
+                   double *s,
+                   double *v)
+{
+  GtkHSVPrivate *priv;
+
+  g_return_if_fail (GTK_IS_HSV (hsv));
+
+  priv = hsv->priv;
+
+  if (h)
+    *h = priv->h;
+
+  if (s)
+    *s = priv->s;
+
+  if (v)
+    *v = priv->v;
+}
+
+/**
+ * gtk_hsv_set_metrics:
+ * @hsv: An HSV color selector
+ * @size: Diameter for the hue ring
+ * @ring_width: Width of the hue ring
+ *
+ * Sets the size and ring width of an HSV color selector.
+ *
+ * Since: 2.14
+ */
+void
+gtk_hsv_set_metrics (GtkHSV *hsv,
+                     gint    size,
+                     gint    ring_width)
+{
+  GtkHSVPrivate *priv;
+  int same_size;
+
+  g_return_if_fail (GTK_IS_HSV (hsv));
+  g_return_if_fail (size > 0);
+  g_return_if_fail (ring_width > 0);
+  g_return_if_fail (2 * ring_width + 1 <= size);
+
+  priv = hsv->priv;
+
+  same_size = (priv->size == size);
+
+  priv->size = size;
+  priv->ring_width = ring_width;
+  
+  if (same_size)
+    gtk_widget_queue_draw (GTK_WIDGET (hsv));
+  else
+    gtk_widget_queue_resize (GTK_WIDGET (hsv));
+}
+
+/**
+ * gtk_hsv_get_metrics:
+ * @hsv: An HSV color selector
+ * @size: (out): Return value for the diameter of the hue ring
+ * @ring_width: (out): Return value for the width of the hue ring
+ *
+ * Queries the size and ring width of an HSV color selector.
+ *
+ * Since: 2.14
+ */
+void
+gtk_hsv_get_metrics (GtkHSV *hsv,
+                     gint   *size,
+                     gint   *ring_width)
+{
+  GtkHSVPrivate *priv;
+
+  g_return_if_fail (GTK_IS_HSV (hsv));
+
+  priv = hsv->priv;
+
+  if (size)
+    *size = priv->size;
+  
+  if (ring_width)
+    *ring_width = priv->ring_width;
+}
+
+/**
+ * gtk_hsv_is_adjusting:
+ * @hsv: A #GtkHSV 
+ *
+ * An HSV color selector can be said to be adjusting if multiple rapid
+ * changes are being made to its value, for example, when the user is 
+ * adjusting the value with the mouse. This function queries whether 
+ * the HSV color selector is being adjusted or not.
+ *
+ * Return value: %TRUE if clients can ignore changes to the color value,
+ *     since they may be transitory, or %FALSE if they should consider
+ *     the color value status to be final.
+ *
+ * Since: 2.14
+ */
+gboolean
+gtk_hsv_is_adjusting (GtkHSV *hsv)
+{
+  GtkHSVPrivate *priv;
+
+  g_return_val_if_fail (GTK_IS_HSV (hsv), FALSE);
+
+  priv = hsv->priv;
+
+  return priv->mode != DRAG_NONE;
+}
+
+static void
+gtk_hsv_move (GtkHSV          *hsv,
+              GtkDirectionType dir)
+{
+  GtkHSVPrivate *priv = hsv->priv;
+  gdouble hue, sat, val;
+  gint hx, hy, sx, sy, vx, vy; /* HSV vertices */
+  gint x, y; /* position in triangle */
+
+  hue = priv->h;
+  sat = priv->s;
+  val = priv->v;
+
+  compute_triangle (hsv, &hx, &hy, &sx, &sy, &vx, &vy);
+
+  x = floor (sx + (vx - sx) * priv->v + (hx - vx) * priv->s * priv->v + 0.5);
+  y = floor (sy + (vy - sy) * priv->v + (hy - vy) * priv->s * priv->v + 0.5);
+
+#define HUE_DELTA 0.002
+  switch (dir)
+    {
+    case GTK_DIR_UP:
+      if (priv->focus_on_ring)
+        hue += HUE_DELTA;
+      else
+        {
+          y -= 1;
+          compute_sv (hsv, x, y, &sat, &val);
+        }
+      break;
+
+    case GTK_DIR_DOWN:
+      if (priv->focus_on_ring)
+        hue -= HUE_DELTA;
+      else
+        {
+          y += 1;
+          compute_sv (hsv, x, y, &sat, &val);
+        }
+      break;
+
+    case GTK_DIR_LEFT:
+      if (priv->focus_on_ring)
+        hue += HUE_DELTA;
+      else
+        {
+          x -= 1;
+          compute_sv (hsv, x, y, &sat, &val);
+        }
+      break;
+
+    case GTK_DIR_RIGHT:
+      if (priv->focus_on_ring)
+        hue -= HUE_DELTA
+          ;
+      else
+        {
+          x += 1;
+          compute_sv (hsv, x, y, &sat, &val);
+        }
+      break;
+
+    default:
+      /* we don't care about the tab directions */
+      break;
+    }
+
+  /* Wrap */
+  if (hue < 0.0)
+    hue = 1.0;
+  else if (hue > 1.0)
+    hue = 0.0;
+  
+  gtk_hsv_set_color (hsv, hue, sat, val);
+}
+
diff --git a/gtk/deprecated/gtkhsv.h b/gtk/deprecated/gtkhsv.h
new file mode 100644 (file)
index 0000000..bdf2694
--- /dev/null
@@ -0,0 +1,108 @@
+/* HSV color selector for GTK+
+ *
+ * Copyright (C) 1999 The Free Software Foundation
+ *
+ * Authors: Simon Budig <Simon.Budig@unix-ag.org> (original code)
+ *          Federico Mena-Quintero <federico@gimp.org> (cleanup for GTK+)
+ *          Jonathan Blandford <jrb@redhat.com> (cleanup for GTK+)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+/*
+ * Modified by the GTK+ Team and others 1997-2000.  See the AUTHORS
+ * file for a list of people on the GTK+ Team.  See the ChangeLog
+ * files for a list of changes.  These files are distributed with
+ * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
+ */
+
+#if !defined (__GTK_H_INSIDE__) && !defined (GTK_COMPILATION)
+#error "Only <gtk/gtk.h> can be included directly."
+#endif
+
+#ifndef __GTK_HSV_H__
+#define __GTK_HSV_H__
+
+#include <gtk/gtkwidget.h>
+
+G_BEGIN_DECLS
+
+#define GTK_TYPE_HSV            (gtk_hsv_get_type ())
+#define GTK_HSV(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_HSV, GtkHSV))
+#define GTK_HSV_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_HSV, GtkHSVClass))
+#define GTK_IS_HSV(obj)         (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_HSV))
+#define GTK_IS_HSV_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_HSV))
+#define GTK_HSV_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_HSV, GtkHSVClass))
+
+
+typedef struct _GtkHSV              GtkHSV;
+typedef struct _GtkHSVPrivate       GtkHSVPrivate;
+typedef struct _GtkHSVClass         GtkHSVClass;
+
+struct _GtkHSV
+{
+  GtkWidget parent_instance;
+
+  /*< private >*/
+  GtkHSVPrivate *priv;
+};
+
+struct _GtkHSVClass
+{
+  GtkWidgetClass parent_class;
+
+  /* Notification signals */
+  void (* changed) (GtkHSV          *hsv);
+
+  /* Keybindings */
+  void (* move)    (GtkHSV          *hsv,
+                    GtkDirectionType type);
+
+  /* Padding for future expansion */
+  void (*_gtk_reserved1) (void);
+  void (*_gtk_reserved2) (void);
+  void (*_gtk_reserved3) (void);
+  void (*_gtk_reserved4) (void);
+};
+
+
+GType      gtk_hsv_get_type     (void) G_GNUC_CONST;
+GDK_DEPRECATED
+GtkWidget* gtk_hsv_new          (void);
+GDK_DEPRECATED
+void       gtk_hsv_set_color    (GtkHSV    *hsv,
+                                double     h,
+                                double     s,
+                                double     v);
+GDK_DEPRECATED
+void       gtk_hsv_get_color    (GtkHSV    *hsv,
+                                gdouble   *h,
+                                gdouble   *s,
+                                gdouble   *v);
+GDK_DEPRECATED
+void       gtk_hsv_set_metrics  (GtkHSV    *hsv,
+                                gint       size,
+                                gint       ring_width);
+GDK_DEPRECATED
+void       gtk_hsv_get_metrics  (GtkHSV    *hsv,
+                                gint      *size,
+                                gint      *ring_width);
+GDK_DEPRECATED
+gboolean   gtk_hsv_is_adjusting (GtkHSV    *hsv);
+
+G_END_DECLS
+
+#endif /* __GTK_HSV_H__ */
index 130d2faf2c582e3b4ae2ca5105820ae955b0e419..6aa44d2e6f7f81bcbcc642839344485a8b4e4969 100644 (file)
--- a/gtk/gtk.h
+++ b/gtk/gtk.h
@@ -81,8 +81,7 @@
 #include <gtk/gtkcolorchooser.h>
 #include <gtk/gtkcolorchooserdialog.h>
 #include <gtk/gtkcolorchooserwidget.h>
-#include <gtk/gtkcolorsel.h>
-#include <gtk/gtkcolorseldialog.h>
+#include <gtk/gtkcolorutils.h>
 #include <gtk/gtkcombobox.h>
 #include <gtk/gtkcomboboxtext.h>
 #include <gtk/gtkcontainer.h>
 #include <gtk/gtkframe.h>
 #include <gtk/gtkgradient.h>
 #include <gtk/gtkgrid.h>
-#include <gtk/gtkhsv.h>
 #include <gtk/gtkiconfactory.h>
 #include <gtk/gtkicontheme.h>
 #include <gtk/gtkiconview.h>
 #include <gtk/gtkwidgetpath.h>
 #include <gtk/gtkwindow.h>
 
+#include <gtk/deprecated/gtkcolorsel.h>
+#include <gtk/deprecated/gtkcolorseldialog.h>
 #include <gtk/deprecated/gtkfontsel.h>
 #include <gtk/deprecated/gtkhandlebox.h>
 #include <gtk/deprecated/gtkhbbox.h>
 #include <gtk/deprecated/gtkhbox.h>
 #include <gtk/deprecated/gtkhpaned.h>
+#include <gtk/deprecated/gtkhsv.h>
 #include <gtk/deprecated/gtkhscale.h>
 #include <gtk/deprecated/gtkhscrollbar.h>
 #include <gtk/deprecated/gtkhseparator.h>
index f71060f85a6b9ee5c112fd612889997f5c8916e7..b35d938acd967563b8e0b4b5bb266d676d449181 100644 (file)
@@ -24,9 +24,9 @@
 #include "gtkcolorchooserwidget.h"
 #include "gtkcoloreditor.h"
 #include "gtkcolorswatch.h"
+#include "gtkcolorutils.h"
 #include "gtkbox.h"
 #include "gtkgrid.h"
-#include "gtkhsv.h"
 #include "gtklabel.h"
 #include "gtkorientable.h"
 #include "gtkprivate.h"
index 80a91c4a5a41cbb4aac859f353263decd0531f09..a34ee369cf3c7bea9a5af1550748b03dcd0d0a98 100644 (file)
 #include "gtkcolorplane.h"
 #include "gtkcolorscale.h"
 #include "gtkcolorswatch.h"
+#include "gtkcolorutils.h"
 #include "gtkgrid.h"
 #include "gtkorientable.h"
 #include "gtkaspectframe.h"
 #include "gtkdrawingarea.h"
 #include "gtkentry.h"
 #include "gtkoverlay.h"
-#include "gtkhsv.h"
 #include "gtkadjustment.h"
 #include "gtklabel.h"
 #include "gtkspinbutton.h"
index efc205cee63990fc31be61c9eec81de1d92d5206..2e7b2a03603d3b488dc4db080794cf37af539b00 100644 (file)
@@ -19,8 +19,8 @@
 
 #include "config.h"
 
-#include "gtkhsv.h"
 #include "gtkcolorplane.h"
+#include "gtkcolorutils.h"
 #include "gtkcontainer.h"
 #include "gtkaccessible.h"
 #include "gtkwindow.h"
index fb0f5dbe8892c393801aec078b2e69a46e3d6b9e..e7ca4bf8361854df70cda0e2f05a2f7469e6ef78 100644 (file)
@@ -20,7 +20,7 @@
 #include "config.h"
 
 #include "gtkcolorscale.h"
-#include "gtkhsv.h"
+#include "gtkcolorutils.h"
 #include "gtkorientable.h"
 #include "gtkstylecontext.h"
 #include "gtkaccessible.h"
diff --git a/gtk/gtkcolorsel.c b/gtk/gtkcolorsel.c
deleted file mode 100644 (file)
index 2f36d3e..0000000
+++ /dev/null
@@ -1,3111 +0,0 @@
-/* GTK - The GIMP Toolkit
- * Copyright (C) 2000 Red Hat, Inc.
- * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
- */
-
-/*
- * Modified by the GTK+ Team and others 1997-2001.  See the AUTHORS
- * file for a list of people on the GTK+ Team.  See the ChangeLog
- * files for a list of changes.  These files are distributed with
- * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
- */
-
-#include "config.h"
-
-#include "gtkcolorsel.h"
-
-#include <math.h>
-#include <string.h>
-
-#include "gdk/gdk.h"
-#include "gtkorientable.h"
-#include "gtkhsv.h"
-#include "gtkwindow.h"
-#include "gtkselection.h"
-#include "gtkdnd.h"
-#include "gtkdrawingarea.h"
-#include "gtkframe.h"
-#include "gtkgrid.h"
-#include "gtklabel.h"
-#include "gtkmarshalers.h"
-#include "gtkimage.h"
-#include "gtkspinbutton.h"
-#include "gtkrange.h"
-#include "gtkscale.h"
-#include "gtkentry.h"
-#include "gtkbutton.h"
-#include "gtkmenuitem.h"
-#include "gtkmain.h"
-#include "gtksettings.h"
-#include "gtkstock.h"
-#include "gtkaccessible.h"
-#include "gtksizerequest.h"
-#include "gtkseparator.h"
-#include "gtkprivate.h"
-#include "gtkintl.h"
-
-
-/**
- * SECTION:gtkcolorsel
- * @Short_description: A widget used to select a color
- * @Title: GtkColorSelection
- *
- * The #GtkColorSelection is a widget that is used to select
- * a color.  It consists of a color wheel and number of sliders
- * and entry boxes for color parameters such as hue, saturation,
- * value, red, green, blue, and opacity.  It is found on the standard
- * color selection dialog box #GtkColorSelectionDialog.
- */
-
-
-/* Keep it in sync with gtksettings.c:default_color_palette */
-#define DEFAULT_COLOR_PALETTE   "black:white:gray50:red:purple:blue:light blue:green:yellow:orange:lavender:brown:goldenrod4:dodger blue:pink:light green:gray10:gray30:gray75:gray90"
-
-/* Number of elements in the custom palatte */
-#define GTK_CUSTOM_PALETTE_WIDTH 10
-#define GTK_CUSTOM_PALETTE_HEIGHT 2
-
-#define CUSTOM_PALETTE_ENTRY_WIDTH   20
-#define CUSTOM_PALETTE_ENTRY_HEIGHT  20
-
-/* The cursor for the dropper */
-#define DROPPER_WIDTH 17
-#define DROPPER_HEIGHT 17
-#define DROPPER_STRIDE (DROPPER_WIDTH * 4)
-#define DROPPER_X_HOT 2
-#define DROPPER_Y_HOT 16
-
-#define SAMPLE_WIDTH  64
-#define SAMPLE_HEIGHT 28
-#define CHECK_SIZE 16
-#define BIG_STEP 20
-
-/* Conversion between 0->1 double and and guint16. See
- * scale_round() below for more general conversions
- */
-#define SCALE(i) (i / 65535.)
-#define UNSCALE(d) ((guint16)(d * 65535 + 0.5))
-#define INTENSITY(r, g, b) ((r) * 0.30 + (g) * 0.59 + (b) * 0.11)
-
-enum {
-  COLOR_CHANGED,
-  LAST_SIGNAL
-};
-
-enum {
-  PROP_0,
-  PROP_HAS_PALETTE,
-  PROP_HAS_OPACITY_CONTROL,
-  PROP_CURRENT_COLOR,
-  PROP_CURRENT_ALPHA,
-  PROP_CURRENT_RGBA
-};
-
-enum {
-  COLORSEL_RED = 0,
-  COLORSEL_GREEN = 1,
-  COLORSEL_BLUE = 2,
-  COLORSEL_OPACITY = 3,
-  COLORSEL_HUE,
-  COLORSEL_SATURATION,
-  COLORSEL_VALUE,
-  COLORSEL_NUM_CHANNELS
-};
-
-
-struct _GtkColorSelectionPrivate
-{
-  guint has_opacity       : 1;
-  guint has_palette       : 1;
-  guint changing          : 1;
-  guint default_set       : 1;
-  guint default_alpha_set : 1;
-  guint has_grab          : 1;
-
-  gdouble color[COLORSEL_NUM_CHANNELS];
-  gdouble old_color[COLORSEL_NUM_CHANNELS];
-
-  GtkWidget *triangle_colorsel;
-  GtkWidget *hue_spinbutton;
-  GtkWidget *sat_spinbutton;
-  GtkWidget *val_spinbutton;
-  GtkWidget *red_spinbutton;
-  GtkWidget *green_spinbutton;
-  GtkWidget *blue_spinbutton;
-  GtkWidget *opacity_slider;
-  GtkWidget *opacity_label;
-  GtkWidget *opacity_entry;
-  GtkWidget *palette_frame;
-  GtkWidget *hex_entry;
-
-  /* The Palette code */
-  GtkWidget *custom_palette [GTK_CUSTOM_PALETTE_WIDTH][GTK_CUSTOM_PALETTE_HEIGHT];
-
-  /* The color_sample stuff */
-  GtkWidget *sample_area;
-  GtkWidget *old_sample;
-  GtkWidget *cur_sample;
-  GtkWidget *colorsel;
-
-  /* Window for grabbing on */
-  GtkWidget *dropper_grab_widget;
-  guint32    grab_time;
-  GdkDevice *keyboard_device;
-  GdkDevice *pointer_device;
-
-  /* Connection to settings */
-  gulong settings_connection;
-};
-
-
-static void gtk_color_selection_destroy         (GtkWidget               *widget);
-static void gtk_color_selection_finalize        (GObject                 *object);
-static void update_color                        (GtkColorSelection       *colorsel);
-static void gtk_color_selection_set_property    (GObject                 *object,
-                                                 guint                    prop_id,
-                                                 const GValue            *value,
-                                                 GParamSpec              *pspec);
-static void gtk_color_selection_get_property    (GObject                 *object,
-                                                 guint                    prop_id,
-                                                 GValue                  *value,
-                                                 GParamSpec              *pspec);
-
-static void gtk_color_selection_realize         (GtkWidget               *widget);
-static void gtk_color_selection_unrealize       (GtkWidget               *widget);
-static void gtk_color_selection_show_all        (GtkWidget               *widget);
-static gboolean gtk_color_selection_grab_broken (GtkWidget               *widget,
-                                                 GdkEventGrabBroken      *event);
-
-static void     gtk_color_selection_set_palette_color   (GtkColorSelection *colorsel,
-                                                         gint               index,
-                                                         GdkColor          *color);
-static void     set_focus_line_attributes               (GtkWidget         *drawing_area,
-                                                         cairo_t           *cr,
-                                                         gint              *focus_width);
-static void     default_noscreen_change_palette_func    (const GdkColor    *colors,
-                                                         gint               n_colors);
-static void     default_change_palette_func             (GdkScreen         *screen,
-                                                         const GdkColor    *colors,
-                                                         gint               n_colors);
-static void     make_control_relations                  (AtkObject         *atk_obj,
-                                                         GtkWidget         *widget);
-static void     make_all_relations                      (AtkObject         *atk_obj,
-                                                         GtkColorSelectionPrivate *priv);
-
-static void     hsv_changed                             (GtkWidget         *hsv,
-                                                         gpointer           data);
-static void     get_screen_color                        (GtkWidget         *button);
-static void     adjustment_changed                      (GtkAdjustment     *adjustment,
-                                                         gpointer           data);
-static void     opacity_entry_changed                   (GtkWidget         *opacity_entry,
-                                                         gpointer           data);
-static void     hex_changed                             (GtkWidget         *hex_entry,
-                                                         gpointer           data);
-static gboolean hex_focus_out                           (GtkWidget         *hex_entry,
-                                                         GdkEventFocus     *event,
-                                                         gpointer           data);
-static void     color_sample_new                        (GtkColorSelection *colorsel);
-static void     make_label_spinbutton                   (GtkColorSelection *colorsel,
-                                                         GtkWidget        **spinbutton,
-                                                         gchar             *text,
-                                                         GtkWidget         *table,
-                                                         gint               i,
-                                                         gint               j,
-                                                         gint               channel_type,
-                                                         const gchar       *tooltip);
-static void     make_palette_frame                      (GtkColorSelection *colorsel,
-                                                         GtkWidget         *table,
-                                                         gint               i,
-                                                         gint               j);
-static void     set_selected_palette                    (GtkColorSelection *colorsel,
-                                                         int                x,
-                                                         int                y);
-static void     set_focus_line_attributes               (GtkWidget         *drawing_area,
-                                                         cairo_t           *cr,
-                                                         gint              *focus_width);
-static gboolean mouse_press                             (GtkWidget         *invisible,
-                                                         GdkEventButton    *event,
-                                                         gpointer           data);
-static void  palette_change_notify_instance (GObject    *object,
-                                             GParamSpec *pspec,
-                                             gpointer    data);
-static void update_palette (GtkColorSelection *colorsel);
-static void shutdown_eyedropper (GtkWidget *widget);
-
-static guint color_selection_signals[LAST_SIGNAL] = { 0 };
-
-static GtkColorSelectionChangePaletteFunc noscreen_change_palette_hook = default_noscreen_change_palette_func;
-static GtkColorSelectionChangePaletteWithScreenFunc change_palette_hook = default_change_palette_func;
-
-static const guchar dropper_bits[] = {
-  "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
-  "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\377\377\377\377\377\377\377\377\377\377"
-  "\377\377\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
-  "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\377\377\377\377\0\0\0\377"
-  "\0\0\0\377\0\0\0\377\377\377\377\377\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
-  "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\377\377\377"
-  "\377\0\0\0\377\0\0\0\377\0\0\0\377\0\0\0\377\0\0\0\377\377\377\377\377"
-  "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\377"
-  "\377\377\377\377\377\377\377\377\377\377\377\0\0\0\377\0\0\0\377\0\0"
-  "\0\377\0\0\0\377\0\0\0\377\377\377\377\377\0\0\0\0\0\0\0\0\0\0\0\0\0"
-  "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\377\377\377\377\0\0\0\377\0\0\0\377\0"
-  "\0\0\377\0\0\0\377\0\0\0\377\0\0\0\377\0\0\0\377\0\0\0\377\377\377\377"
-  "\377\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
-  "\377\377\377\377\0\0\0\377\0\0\0\377\0\0\0\377\0\0\0\377\0\0\0\377\0"
-  "\0\0\377\377\377\377\377\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
-  "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\377\377\377\377\377\0\0\0\377\0\0"
-  "\0\377\0\0\0\377\377\377\377\377\377\377\377\377\0\0\0\0\0\0\0\0\0\0"
-  "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\377\377\377"
-  "\377\377\377\377\377\377\377\377\377\377\0\0\0\377\0\0\0\377\377\377"
-  "\377\377\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
-  "\0\0\0\0\0\0\0\0\0\377\377\377\377\377\377\377\377\377\377\377\377\377"
-  "\0\0\0\377\377\377\377\377\0\0\0\377\377\377\377\377\0\0\0\0\0\0\0\0"
-  "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\377\377\377\377"
-  "\377\377\377\377\377\377\377\377\377\0\0\0\377\0\0\0\0\0\0\0\0\377\377"
-  "\377\377\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
-  "\0\0\0\0\0\377\377\377\377\377\377\377\377\377\377\377\377\377\0\0\0"
-  "\377\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
-  "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\377\377\377\377\377\377\377\377\377\377"
-  "\377\377\377\0\0\0\377\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
-  "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\377\377\377\377\377"
-  "\377\377\377\377\377\377\377\377\0\0\0\377\0\0\0\0\0\0\0\0\0\0\0\0\0"
-  "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
-  "\377\377\377\377\377\377\377\377\377\377\377\377\377\0\0\0\377\0\0\0"
-  "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
-  "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\377\377\377\377\377\377\377\377\377\0\0"
-  "\0\377\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
-  "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\377\0\0\0\0\0\0\0\377\0\0\0"
-  "\377\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
-  "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\377\0\0\0\0\0"
-  "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
-  "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"};
-
-G_DEFINE_TYPE (GtkColorSelection, gtk_color_selection, GTK_TYPE_BOX)
-
-static void
-gtk_color_selection_class_init (GtkColorSelectionClass *klass)
-{
-  GObjectClass *gobject_class;
-  GtkWidgetClass *widget_class;
-
-  gobject_class = G_OBJECT_CLASS (klass);
-  gobject_class->finalize = gtk_color_selection_finalize;
-  gobject_class->set_property = gtk_color_selection_set_property;
-  gobject_class->get_property = gtk_color_selection_get_property;
-
-  widget_class = GTK_WIDGET_CLASS (klass);
-  widget_class->destroy = gtk_color_selection_destroy;
-  widget_class->realize = gtk_color_selection_realize;
-  widget_class->unrealize = gtk_color_selection_unrealize;
-  widget_class->show_all = gtk_color_selection_show_all;
-  widget_class->grab_broken_event = gtk_color_selection_grab_broken;
-
-  g_object_class_install_property (gobject_class,
-                                   PROP_HAS_OPACITY_CONTROL,
-                                   g_param_spec_boolean ("has-opacity-control",
-                                                         P_("Has Opacity Control"),
-                                                         P_("Whether the color selector should allow setting opacity"),
-                                                         FALSE,
-                                                         GTK_PARAM_READWRITE));
-  g_object_class_install_property (gobject_class,
-                                   PROP_HAS_PALETTE,
-                                   g_param_spec_boolean ("has-palette",
-                                                         P_("Has palette"),
-                                                         P_("Whether a palette should be used"),
-                                                         FALSE,
-                                                         GTK_PARAM_READWRITE));
-
-  /**
-   * GtkColorSelection:current-color
-   *
-   * The current GdkColor color.
-   *
-   * Deprecated: 3.4: Use #GtkColorSelection:current-rgba instead.
-   */
-  g_object_class_install_property (gobject_class,
-                                   PROP_CURRENT_COLOR,
-                                   g_param_spec_boxed ("current-color",
-                                                       P_("Current Color"),
-                                                       P_("The current color"),
-                                                       GDK_TYPE_COLOR,
-                                                       GTK_PARAM_READWRITE | G_PARAM_DEPRECATED));
-  g_object_class_install_property (gobject_class,
-                                   PROP_CURRENT_ALPHA,
-                                   g_param_spec_uint ("current-alpha",
-                                                      P_("Current Alpha"),
-                                                      P_("The current opacity value (0 fully transparent, 65535 fully opaque)"),
-                                                      0, 65535, 65535,
-                                                      GTK_PARAM_READWRITE));
-
-  /**
-   * GtkColorSelection:current-rgba
-   *
-   * The current RGBA color.
-   *
-   * Since: 3.0
-   */
-  g_object_class_install_property (gobject_class,
-                                   PROP_CURRENT_RGBA,
-                                   g_param_spec_boxed ("current-rgba",
-                                                       P_("Current RGBA"),
-                                                       P_("The current RGBA color"),
-                                                       GDK_TYPE_RGBA,
-                                                       GTK_PARAM_READWRITE));
-
-  /**
-   * GtkColorSelection::color-changed:
-   * @colorselection: the object which received the signal.
-   *
-   * This signal is emitted when the color changes in the #GtkColorSelection
-   * according to its update policy.
-   */
-  color_selection_signals[COLOR_CHANGED] =
-    g_signal_new (I_("color-changed"),
-                  G_OBJECT_CLASS_TYPE (gobject_class),
-                  G_SIGNAL_RUN_FIRST,
-                  G_STRUCT_OFFSET (GtkColorSelectionClass, color_changed),
-                  NULL, NULL,
-                  _gtk_marshal_VOID__VOID,
-                  G_TYPE_NONE, 0);
-
-  g_type_class_add_private (gobject_class, sizeof (GtkColorSelectionPrivate));
-}
-
-static void
-gtk_color_selection_init (GtkColorSelection *colorsel)
-{
-  GtkWidget *top_hbox;
-  GtkWidget *top_right_vbox;
-  GtkWidget *table, *label, *hbox, *frame, *vbox, *button;
-  GtkAdjustment *adjust;
-  GtkWidget *picker_image;
-  gint i, j;
-  GtkColorSelectionPrivate *priv;
-  AtkObject *atk_obj;
-  GList *focus_chain = NULL;
-
-  gtk_orientable_set_orientation (GTK_ORIENTABLE (colorsel),
-                                  GTK_ORIENTATION_VERTICAL);
-
-  gtk_widget_push_composite_child ();
-
-  priv = colorsel->private_data = G_TYPE_INSTANCE_GET_PRIVATE (colorsel, GTK_TYPE_COLOR_SELECTION, GtkColorSelectionPrivate);
-  priv->changing = FALSE;
-  priv->default_set = FALSE;
-  priv->default_alpha_set = FALSE;
-
-  top_hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 12);
-  gtk_box_pack_start (GTK_BOX (colorsel), top_hbox, FALSE, FALSE, 0);
-
-  vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6);
-  priv->triangle_colorsel = gtk_hsv_new ();
-  g_signal_connect (priv->triangle_colorsel, "changed",
-                    G_CALLBACK (hsv_changed), colorsel);
-  gtk_hsv_set_metrics (GTK_HSV (priv->triangle_colorsel), 174, 15);
-  gtk_box_pack_start (GTK_BOX (top_hbox), vbox, FALSE, FALSE, 0);
-  gtk_box_pack_start (GTK_BOX (vbox), priv->triangle_colorsel, FALSE, FALSE, 0);
-  gtk_widget_set_tooltip_text (priv->triangle_colorsel,
-                        _("Select the color you want from the outer ring. "
-                          "Select the darkness or lightness of that color "
-                          "using the inner triangle."));
-
-  hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
-  gtk_box_pack_end (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
-
-  frame = gtk_frame_new (NULL);
-  gtk_widget_set_size_request (frame, -1, 30);
-  gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_IN);
-  color_sample_new (colorsel);
-  gtk_container_add (GTK_CONTAINER (frame), priv->sample_area);
-  gtk_box_pack_start (GTK_BOX (hbox), frame, TRUE, TRUE, 0);
-
-  button = gtk_button_new ();
-
-  gtk_widget_set_events (button, GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK);
-  g_object_set_data (G_OBJECT (button), I_("COLORSEL"), colorsel);
-  g_signal_connect (button, "clicked",
-                    G_CALLBACK (get_screen_color), NULL);
-  picker_image = gtk_image_new_from_stock (GTK_STOCK_COLOR_PICKER, GTK_ICON_SIZE_BUTTON);
-  gtk_container_add (GTK_CONTAINER (button), picker_image);
-  gtk_widget_show (GTK_WIDGET (picker_image));
-  gtk_box_pack_end (GTK_BOX (hbox), button, FALSE, FALSE, 0);
-
-  gtk_widget_set_tooltip_text (button,
-                        _("Click the eyedropper, then click a color "
-                          "anywhere on your screen to select that color."));
-
-  top_right_vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6);
-  gtk_box_pack_start (GTK_BOX (top_hbox), top_right_vbox, FALSE, FALSE, 0);
-  table = gtk_grid_new ();
-  gtk_box_pack_start (GTK_BOX (top_right_vbox), table, FALSE, FALSE, 0);
-  gtk_grid_set_row_spacing (GTK_GRID (table), 6);
-  gtk_grid_set_column_spacing (GTK_GRID (table), 12);
-
-  make_label_spinbutton (colorsel, &priv->hue_spinbutton, _("_Hue:"), table, 0, 0, COLORSEL_HUE,
-                         _("Position on the color wheel."));
-  gtk_spin_button_set_wrap (GTK_SPIN_BUTTON (priv->hue_spinbutton), TRUE);
-  make_label_spinbutton (colorsel, &priv->sat_spinbutton, _("S_aturation:"), table, 0, 1, COLORSEL_SATURATION,
-                         _("Intensity of the color."));
-  make_label_spinbutton (colorsel, &priv->val_spinbutton, _("_Value:"), table, 0, 2, COLORSEL_VALUE,
-                         _("Brightness of the color."));
-  make_label_spinbutton (colorsel, &priv->red_spinbutton, _("_Red:"), table, 6, 0, COLORSEL_RED,
-                         _("Amount of red light in the color."));
-  make_label_spinbutton (colorsel, &priv->green_spinbutton, _("_Green:"), table, 6, 1, COLORSEL_GREEN,
-                         _("Amount of green light in the color."));
-  make_label_spinbutton (colorsel, &priv->blue_spinbutton, _("_Blue:"), table, 6, 2, COLORSEL_BLUE,
-                         _("Amount of blue light in the color."));
-  gtk_grid_attach (GTK_GRID (table), gtk_separator_new (GTK_ORIENTATION_HORIZONTAL), 0, 3, 8, 1);
-
-  priv->opacity_label = gtk_label_new_with_mnemonic (_("Op_acity:"));
-  gtk_widget_set_halign (priv->opacity_label, GTK_ALIGN_START);
-  gtk_widget_set_valign (priv->opacity_label, GTK_ALIGN_CENTER);
-  gtk_grid_attach (GTK_GRID (table), priv->opacity_label, 0, 4, 1, 1);
-  adjust = gtk_adjustment_new (0.0, 0.0, 255.0, 1.0, 1.0, 0.0);
-  g_object_set_data (G_OBJECT (adjust), I_("COLORSEL"), colorsel);
-  priv->opacity_slider = gtk_scale_new (GTK_ORIENTATION_HORIZONTAL, adjust);
-  gtk_widget_set_tooltip_text (priv->opacity_slider,
-                        _("Transparency of the color."));
-  gtk_label_set_mnemonic_widget (GTK_LABEL (priv->opacity_label),
-                                 priv->opacity_slider);
-  gtk_scale_set_draw_value (GTK_SCALE (priv->opacity_slider), FALSE);
-  g_signal_connect (adjust, "value-changed",
-                    G_CALLBACK (adjustment_changed),
-                    GINT_TO_POINTER (COLORSEL_OPACITY));
-  gtk_grid_attach (GTK_GRID (table), priv->opacity_slider, 1, 4, 6, 1);
-  priv->opacity_entry = gtk_entry_new ();
-  gtk_widget_set_tooltip_text (priv->opacity_entry,
-                        _("Transparency of the color."));
-  gtk_widget_set_size_request (priv->opacity_entry, 40, -1);
-
-  g_signal_connect (priv->opacity_entry, "activate",
-                    G_CALLBACK (opacity_entry_changed), colorsel);
-  gtk_grid_attach (GTK_GRID (table), priv->opacity_entry, 7, 4, 1, 1);
-
-  label = gtk_label_new_with_mnemonic (_("Color _name:"));
-  gtk_grid_attach (GTK_GRID (table), label, 0, 5, 1, 1);
-  gtk_widget_set_halign (label, GTK_ALIGN_START);
-  gtk_widget_set_valign (label, GTK_ALIGN_CENTER);
-  priv->hex_entry = gtk_entry_new ();
-
-  gtk_label_set_mnemonic_widget (GTK_LABEL (label), priv->hex_entry);
-
-  g_signal_connect (priv->hex_entry, "activate",
-                    G_CALLBACK (hex_changed), colorsel);
-
-  g_signal_connect (priv->hex_entry, "focus-out-event",
-                    G_CALLBACK (hex_focus_out), colorsel);
-
-  gtk_widget_set_tooltip_text (priv->hex_entry,
-                        _("You can enter an HTML-style hexadecimal color "
-                          "value, or simply a color name such as 'orange' "
-                          "in this entry."));
-
-  gtk_entry_set_width_chars (GTK_ENTRY (priv->hex_entry), 7);
-  gtk_grid_attach (GTK_GRID (table), priv->hex_entry, 1, 5, 4, 1);
-
-  focus_chain = g_list_append (focus_chain, priv->hue_spinbutton);
-  focus_chain = g_list_append (focus_chain, priv->sat_spinbutton);
-  focus_chain = g_list_append (focus_chain, priv->val_spinbutton);
-  focus_chain = g_list_append (focus_chain, priv->red_spinbutton);
-  focus_chain = g_list_append (focus_chain, priv->green_spinbutton);
-  focus_chain = g_list_append (focus_chain, priv->blue_spinbutton);
-  focus_chain = g_list_append (focus_chain, priv->opacity_slider);
-  focus_chain = g_list_append (focus_chain, priv->opacity_entry);
-  focus_chain = g_list_append (focus_chain, priv->hex_entry);
-  gtk_container_set_focus_chain (GTK_CONTAINER (table), focus_chain);
-  g_list_free (focus_chain);
-
-  /* Set up the palette */
-  table = gtk_grid_new ();
-  gtk_grid_set_row_spacing (GTK_GRID (table), 1);
-  gtk_grid_set_column_spacing (GTK_GRID (table), 1);
-  for (i = 0; i < GTK_CUSTOM_PALETTE_WIDTH; i++)
-    {
-      for (j = 0; j < GTK_CUSTOM_PALETTE_HEIGHT; j++)
-        {
-          make_palette_frame (colorsel, table, i, j);
-        }
-    }
-  set_selected_palette (colorsel, 0, 0);
-  priv->palette_frame = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6);
-  label = gtk_label_new_with_mnemonic (_("_Palette:"));
-  gtk_widget_set_halign (label, GTK_ALIGN_START);
-  gtk_widget_set_valign (label, GTK_ALIGN_CENTER);
-  gtk_box_pack_start (GTK_BOX (priv->palette_frame), label, FALSE, FALSE, 0);
-
-  gtk_label_set_mnemonic_widget (GTK_LABEL (label),
-                                 priv->custom_palette[0][0]);
-
-  gtk_box_pack_end (GTK_BOX (top_right_vbox), priv->palette_frame, FALSE, FALSE, 0);
-  gtk_box_pack_start (GTK_BOX (priv->palette_frame), table, FALSE, FALSE, 0);
-
-  gtk_widget_show_all (top_hbox);
-
-  /* hide unused stuff */
-
-  if (priv->has_opacity == FALSE)
-    {
-      gtk_widget_hide (priv->opacity_label);
-      gtk_widget_hide (priv->opacity_slider);
-      gtk_widget_hide (priv->opacity_entry);
-    }
-
-  if (priv->has_palette == FALSE)
-    {
-      gtk_widget_hide (priv->palette_frame);
-    }
-
-  atk_obj = gtk_widget_get_accessible (priv->triangle_colorsel);
-  if (GTK_IS_ACCESSIBLE (atk_obj))
-    {
-      atk_object_set_name (atk_obj, _("Color Wheel"));
-      atk_object_set_role (gtk_widget_get_accessible (GTK_WIDGET (colorsel)), ATK_ROLE_COLOR_CHOOSER);
-      make_all_relations (atk_obj, priv);
-    }
-
-  gtk_widget_pop_composite_child ();
-}
-
-/* GObject methods */
-static void
-gtk_color_selection_finalize (GObject *object)
-{
-  G_OBJECT_CLASS (gtk_color_selection_parent_class)->finalize (object);
-}
-
-static void
-gtk_color_selection_set_property (GObject         *object,
-                                  guint            prop_id,
-                                  const GValue    *value,
-                                  GParamSpec      *pspec)
-{
-  GtkColorSelection *colorsel = GTK_COLOR_SELECTION (object);
-
-  switch (prop_id)
-    {
-    case PROP_HAS_OPACITY_CONTROL:
-      gtk_color_selection_set_has_opacity_control (colorsel,
-                                                   g_value_get_boolean (value));
-      break;
-    case PROP_HAS_PALETTE:
-      gtk_color_selection_set_has_palette (colorsel,
-                                           g_value_get_boolean (value));
-      break;
-    case PROP_CURRENT_COLOR:
-      {
-        GdkColor *color;
-        GdkRGBA rgba;
-
-        color = g_value_get_boxed (value);
-
-        rgba.red = SCALE (color->red);
-        rgba.green = SCALE (color->green);;
-        rgba.blue = SCALE (color->blue);
-        rgba.alpha = 1.0;
-
-        gtk_color_selection_set_current_rgba (colorsel, &rgba);
-      }
-      break;
-    case PROP_CURRENT_ALPHA:
-      gtk_color_selection_set_current_alpha (colorsel, g_value_get_uint (value));
-      break;
-    case PROP_CURRENT_RGBA:
-      gtk_color_selection_set_current_rgba (colorsel, g_value_get_boxed (value));
-      break;
-    default:
-      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
-      break;
-    }
-
-}
-
-static void
-gtk_color_selection_get_property (GObject     *object,
-                                  guint        prop_id,
-                                  GValue      *value,
-                                  GParamSpec  *pspec)
-{
-  GtkColorSelection *colorsel = GTK_COLOR_SELECTION (object);
-
-  switch (prop_id)
-    {
-    case PROP_HAS_OPACITY_CONTROL:
-      g_value_set_boolean (value, gtk_color_selection_get_has_opacity_control (colorsel));
-      break;
-    case PROP_HAS_PALETTE:
-      g_value_set_boolean (value, gtk_color_selection_get_has_palette (colorsel));
-      break;
-    case PROP_CURRENT_COLOR:
-      {
-        GdkColor color;
-        GdkRGBA rgba;
-
-        gtk_color_selection_get_current_rgba (colorsel, &rgba);
-
-        color.red = UNSCALE (rgba.red);
-        color.green = UNSCALE (rgba.green);
-        color.blue = UNSCALE (rgba.blue);
-
-        g_value_set_boxed (value, &color);
-      }
-      break;
-    case PROP_CURRENT_ALPHA:
-      g_value_set_uint (value, gtk_color_selection_get_current_alpha (colorsel));
-      break;
-    case PROP_CURRENT_RGBA:
-      {
-        GdkRGBA rgba;
-
-        gtk_color_selection_get_current_rgba (colorsel, &rgba);
-        g_value_set_boxed (value, &rgba);
-      }
-      break;
-    default:
-      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
-      break;
-    }
-}
-
-/* GtkWidget methods */
-
-static void
-gtk_color_selection_destroy (GtkWidget *widget)
-{
-  GtkColorSelection *cselection = GTK_COLOR_SELECTION (widget);
-  GtkColorSelectionPrivate *priv = cselection->private_data;
-
-  if (priv->dropper_grab_widget)
-    {
-      gtk_widget_destroy (priv->dropper_grab_widget);
-      priv->dropper_grab_widget = NULL;
-    }
-
-  GTK_WIDGET_CLASS (gtk_color_selection_parent_class)->destroy (widget);
-}
-
-static void
-gtk_color_selection_realize (GtkWidget *widget)
-{
-  GtkColorSelection *colorsel = GTK_COLOR_SELECTION (widget);
-  GtkColorSelectionPrivate *priv = colorsel->private_data;
-  GtkSettings *settings = gtk_widget_get_settings (widget);
-
-  priv->settings_connection =  g_signal_connect (settings,
-                                                 "notify::gtk-color-palette",
-                                                 G_CALLBACK (palette_change_notify_instance),
-                                                 widget);
-  update_palette (colorsel);
-
-  GTK_WIDGET_CLASS (gtk_color_selection_parent_class)->realize (widget);
-}
-
-static void
-gtk_color_selection_unrealize (GtkWidget *widget)
-{
-  GtkColorSelection *colorsel = GTK_COLOR_SELECTION (widget);
-  GtkColorSelectionPrivate *priv = colorsel->private_data;
-  GtkSettings *settings = gtk_widget_get_settings (widget);
-
-  g_signal_handler_disconnect (settings, priv->settings_connection);
-
-  GTK_WIDGET_CLASS (gtk_color_selection_parent_class)->unrealize (widget);
-}
-
-/* We override show-all since we have internal widgets that
- * shouldn't be shown when you call show_all(), like the
- * palette and opacity sliders.
- */
-static void
-gtk_color_selection_show_all (GtkWidget *widget)
-{
-  gtk_widget_show (widget);
-}
-
-static gboolean
-gtk_color_selection_grab_broken (GtkWidget          *widget,
-                                 GdkEventGrabBroken *event)
-{
-  shutdown_eyedropper (widget);
-
-  return TRUE;
-}
-
-/*
- *
- * The Sample Color
- *
- */
-
-static void color_sample_draw_sample (GtkColorSelection *colorsel,
-                                      int                which,
-                                      cairo_t *          cr);
-static void color_sample_update_samples (GtkColorSelection *colorsel);
-
-static void
-set_color_internal (GtkColorSelection *colorsel,
-                    gdouble           *color)
-{
-  GtkColorSelectionPrivate *priv;
-  gint i;
-
-  priv = colorsel->private_data;
-  priv->changing = TRUE;
-  priv->color[COLORSEL_RED] = color[0];
-  priv->color[COLORSEL_GREEN] = color[1];
-  priv->color[COLORSEL_BLUE] = color[2];
-  priv->color[COLORSEL_OPACITY] = color[3];
-  gtk_rgb_to_hsv (priv->color[COLORSEL_RED],
-                  priv->color[COLORSEL_GREEN],
-                  priv->color[COLORSEL_BLUE],
-                  &priv->color[COLORSEL_HUE],
-                  &priv->color[COLORSEL_SATURATION],
-                  &priv->color[COLORSEL_VALUE]);
-  if (priv->default_set == FALSE)
-    {
-      for (i = 0; i < COLORSEL_NUM_CHANNELS; i++)
-        priv->old_color[i] = priv->color[i];
-    }
-  priv->default_set = TRUE;
-  priv->default_alpha_set = TRUE;
-  update_color (colorsel);
-}
-
-static void
-set_color_icon (GdkDragContext *context,
-                gdouble        *colors)
-{
-  GdkPixbuf *pixbuf;
-  guint32 pixel;
-
-  pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, FALSE,
-                           8, 48, 32);
-
-  pixel = (((UNSCALE (colors[COLORSEL_RED])   & 0xff00) << 16) |
-           ((UNSCALE (colors[COLORSEL_GREEN]) & 0xff00) << 8) |
-           ((UNSCALE (colors[COLORSEL_BLUE])  & 0xff00)));
-
-  gdk_pixbuf_fill (pixbuf, pixel);
-
-  gtk_drag_set_icon_pixbuf (context, pixbuf, -2, -2);
-  g_object_unref (pixbuf);
-}
-
-static void
-color_sample_drag_begin (GtkWidget      *widget,
-                         GdkDragContext *context,
-                         gpointer        data)
-{
-  GtkColorSelection *colorsel = data;
-  GtkColorSelectionPrivate *priv;
-  gdouble *colsrc;
-
-  priv = colorsel->private_data;
-
-  if (widget == priv->old_sample)
-    colsrc = priv->old_color;
-  else
-    colsrc = priv->color;
-
-  set_color_icon (context, colsrc);
-}
-
-static void
-color_sample_drag_end (GtkWidget      *widget,
-                       GdkDragContext *context,
-                       gpointer        data)
-{
-  g_object_set_data (G_OBJECT (widget), I_("gtk-color-selection-drag-window"), NULL);
-}
-
-static void
-color_sample_drop_handle (GtkWidget        *widget,
-                          GdkDragContext   *context,
-                          gint              x,
-                          gint              y,
-                          GtkSelectionData *selection_data,
-                          guint             info,
-                          guint             time,
-                          gpointer          data)
-{
-  GtkColorSelection *colorsel = data;
-  GtkColorSelectionPrivate *priv;
-  gint length;
-  guint16 *vals;
-  gdouble color[4];
-  priv = colorsel->private_data;
-
-  /* This is currently a guint16 array of the format:
-   * R
-   * G
-   * B
-   * opacity
-   */
-
-  length = gtk_selection_data_get_length (selection_data);
-
-  if (length < 0)
-    return;
-
-  /* We accept drops with the wrong format, since the KDE color
-   * chooser incorrectly drops application/x-color with format 8.
-   */
-  if (length != 8)
-    {
-      g_warning ("Received invalid color data\n");
-      return;
-    }
-
-  vals = (guint16 *) gtk_selection_data_get_data (selection_data);
-
-  if (widget == priv->cur_sample)
-    {
-      color[0] = (gdouble)vals[0] / 0xffff;
-      color[1] = (gdouble)vals[1] / 0xffff;
-      color[2] = (gdouble)vals[2] / 0xffff;
-      color[3] = (gdouble)vals[3] / 0xffff;
-
-      set_color_internal (colorsel, color);
-    }
-}
-
-static void
-color_sample_drag_handle (GtkWidget        *widget,
-                          GdkDragContext   *context,
-                          GtkSelectionData *selection_data,
-                          guint             info,
-                          guint             time,
-                          gpointer          data)
-{
-  GtkColorSelection *colorsel = data;
-  GtkColorSelectionPrivate *priv;
-  guint16 vals[4];
-  gdouble *colsrc;
-
-  priv = colorsel->private_data;
-
-  if (widget == priv->old_sample)
-    colsrc = priv->old_color;
-  else
-    colsrc = priv->color;
-
-  vals[0] = colsrc[COLORSEL_RED] * 0xffff;
-  vals[1] = colsrc[COLORSEL_GREEN] * 0xffff;
-  vals[2] = colsrc[COLORSEL_BLUE] * 0xffff;
-  vals[3] = priv->has_opacity ? colsrc[COLORSEL_OPACITY] * 0xffff : 0xffff;
-
-  gtk_selection_data_set (selection_data,
-                          gdk_atom_intern_static_string ("application/x-color"),
-                          16, (guchar *)vals, 8);
-}
-
-/* which = 0 means draw old sample, which = 1 means draw new */
-static void
-color_sample_draw_sample (GtkColorSelection *colorsel,
-                          int                which,
-                          cairo_t           *cr)
-{
-  GtkWidget *da;
-  gint x, y, goff;
-  GtkColorSelectionPrivate *priv;
-  int width, height;
-
-  g_return_if_fail (colorsel != NULL);
-  priv = colorsel->private_data;
-
-  g_return_if_fail (priv->sample_area != NULL);
-  if (!gtk_widget_is_drawable (priv->sample_area))
-    return;
-
-  if (which == 0)
-    {
-      da = priv->old_sample;
-      goff = 0;
-    }
-  else
-    {
-      GtkAllocation old_sample_allocation;
-
-      da = priv->cur_sample;
-      gtk_widget_get_allocation (priv->old_sample, &old_sample_allocation);
-      goff =  old_sample_allocation.width % 32;
-    }
-
-  /* Below needs tweaking for non-power-of-two */
-  width = gtk_widget_get_allocated_width (da);
-  height = gtk_widget_get_allocated_height (da);
-
-  if (priv->has_opacity)
-    {
-      /* Draw checks in background */
-
-      cairo_set_source_rgb (cr, 0.5, 0.5, 0.5);
-      cairo_rectangle (cr, 0, 0, width, height);
-      cairo_fill (cr);
-
-      cairo_set_source_rgb (cr, 0.75, 0.75, 0.75);
-      for (x = goff & -CHECK_SIZE; x < goff + width; x += CHECK_SIZE)
-        for (y = 0; y < height; y += CHECK_SIZE)
-          if ((x / CHECK_SIZE + y / CHECK_SIZE) % 2 == 0)
-            cairo_rectangle (cr, x - goff, y, CHECK_SIZE, CHECK_SIZE);
-      cairo_fill (cr);
-    }
-
-  if (which == 0)
-    {
-      cairo_set_source_rgba (cr,
-                             priv->old_color[COLORSEL_RED],
-                             priv->old_color[COLORSEL_GREEN],
-                             priv->old_color[COLORSEL_BLUE],
-                             priv->has_opacity ?
-                                priv->old_color[COLORSEL_OPACITY] : 1.0);
-    }
-  else
-    {
-      cairo_set_source_rgba (cr,
-                             priv->color[COLORSEL_RED],
-                             priv->color[COLORSEL_GREEN],
-                             priv->color[COLORSEL_BLUE],
-                             priv->has_opacity ?
-                               priv->color[COLORSEL_OPACITY] : 1.0);
-    }
-
-  cairo_rectangle (cr, 0, 0, width, height);
-  cairo_fill (cr);
-}
-
-
-static void
-color_sample_update_samples (GtkColorSelection *colorsel)
-{
-  GtkColorSelectionPrivate *priv = colorsel->private_data;
-  gtk_widget_queue_draw (priv->old_sample);
-  gtk_widget_queue_draw (priv->cur_sample);
-}
-
-static gboolean
-color_old_sample_draw (GtkWidget         *da,
-                       cairo_t           *cr,
-                       GtkColorSelection *colorsel)
-{
-  color_sample_draw_sample (colorsel, 0, cr);
-  return FALSE;
-}
-
-
-static gboolean
-color_cur_sample_draw (GtkWidget         *da,
-                       cairo_t           *cr,
-                       GtkColorSelection *colorsel)
-{
-  color_sample_draw_sample (colorsel, 1, cr);
-  return FALSE;
-}
-
-static void
-color_sample_setup_dnd (GtkColorSelection *colorsel, GtkWidget *sample)
-{
-  static const GtkTargetEntry targets[] = {
-    { "application/x-color", 0 }
-  };
-  GtkColorSelectionPrivate *priv;
-  priv = colorsel->private_data;
-
-  gtk_drag_source_set (sample,
-                       GDK_BUTTON1_MASK | GDK_BUTTON3_MASK,
-                       targets, 1,
-                       GDK_ACTION_COPY | GDK_ACTION_MOVE);
-
-  g_signal_connect (sample, "drag-begin",
-                    G_CALLBACK (color_sample_drag_begin),
-                    colorsel);
-  if (sample == priv->cur_sample)
-    {
-
-      gtk_drag_dest_set (sample,
-                         GTK_DEST_DEFAULT_HIGHLIGHT |
-                         GTK_DEST_DEFAULT_MOTION |
-                         GTK_DEST_DEFAULT_DROP,
-                         targets, 1,
-                         GDK_ACTION_COPY);
-
-      g_signal_connect (sample, "drag-end",
-                        G_CALLBACK (color_sample_drag_end),
-                        colorsel);
-    }
-
-  g_signal_connect (sample, "drag-data-get",
-                    G_CALLBACK (color_sample_drag_handle),
-                    colorsel);
-  g_signal_connect (sample, "drag-data-received",
-                    G_CALLBACK (color_sample_drop_handle),
-                    colorsel);
-
-}
-
-static void
-update_tooltips (GtkColorSelection *colorsel)
-{
-  GtkColorSelectionPrivate *priv;
-
-  priv = colorsel->private_data;
-
-  if (priv->has_palette == TRUE)
-    {
-      gtk_widget_set_tooltip_text (priv->old_sample,
-        _("The previously-selected color, for comparison to the color "
-          "you're selecting now. You can drag this color to a palette "
-          "entry, or select this color as current by dragging it to the "
-          "other color swatch alongside."));
-
-      gtk_widget_set_tooltip_text (priv->cur_sample,
-        _("The color you've chosen. You can drag this color to a palette "
-          "entry to save it for use in the future."));
-    }
-  else
-    {
-      gtk_widget_set_tooltip_text (priv->old_sample,
-        _("The previously-selected color, for comparison to the color "
-          "you're selecting now."));
-
-      gtk_widget_set_tooltip_text (priv->cur_sample,
-        _("The color you've chosen."));
-    }
-}
-
-static void
-color_sample_new (GtkColorSelection *colorsel)
-{
-  GtkColorSelectionPrivate *priv;
-
-  priv = colorsel->private_data;
-
-  priv->sample_area = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
-  priv->old_sample = gtk_drawing_area_new ();
-  priv->cur_sample = gtk_drawing_area_new ();
-
-  gtk_box_pack_start (GTK_BOX (priv->sample_area), priv->old_sample,
-                      TRUE, TRUE, 0);
-  gtk_box_pack_start (GTK_BOX (priv->sample_area), priv->cur_sample,
-                      TRUE, TRUE, 0);
-
-  g_signal_connect (priv->old_sample, "draw",
-                    G_CALLBACK (color_old_sample_draw),
-                    colorsel);
-  g_signal_connect (priv->cur_sample, "draw",
-                    G_CALLBACK (color_cur_sample_draw),
-                    colorsel);
-
-  color_sample_setup_dnd (colorsel, priv->old_sample);
-  color_sample_setup_dnd (colorsel, priv->cur_sample);
-
-  update_tooltips (colorsel);
-
-  gtk_widget_show_all (priv->sample_area);
-}
-
-
-/* The palette area code */
-
-static void
-palette_get_color (GtkWidget *drawing_area, gdouble *color)
-{
-  gdouble *color_val;
-
-  g_return_if_fail (color != NULL);
-
-  color_val = g_object_get_data (G_OBJECT (drawing_area), "color_val");
-  if (color_val == NULL)
-    {
-      /* Default to white for no good reason */
-      color[0] = 1.0;
-      color[1] = 1.0;
-      color[2] = 1.0;
-      color[3] = 1.0;
-      return;
-    }
-
-  color[0] = color_val[0];
-  color[1] = color_val[1];
-  color[2] = color_val[2];
-  color[3] = 1.0;
-}
-
-static gboolean
-palette_draw (GtkWidget *drawing_area,
-               cairo_t   *cr,
-               gpointer   data)
-{
-  GtkStyleContext *context;
-  gint focus_width;
-  GdkRGBA color;
-
-  context = gtk_widget_get_style_context (drawing_area);
-  gtk_style_context_get_background_color (context, 0, &color);
-  gdk_cairo_set_source_rgba (cr, &color);
-  cairo_paint (cr);
-
-  if (gtk_widget_has_visible_focus (drawing_area))
-    {
-      set_focus_line_attributes (drawing_area, cr, &focus_width);
-
-      cairo_rectangle (cr,
-                       focus_width / 2., focus_width / 2.,
-                       gtk_widget_get_allocated_width (drawing_area) - focus_width,
-                       gtk_widget_get_allocated_height (drawing_area) - focus_width);
-      cairo_stroke (cr);
-    }
-
-  return FALSE;
-}
-
-static void
-set_focus_line_attributes (GtkWidget *drawing_area,
-                           cairo_t   *cr,
-                           gint      *focus_width)
-{
-  gdouble color[4];
-  gint8 *dash_list;
-
-  gtk_widget_style_get (drawing_area,
-                        "focus-line-width", focus_width,
-                        "focus-line-pattern", (gchar *)&dash_list,
-                        NULL);
-
-  palette_get_color (drawing_area, color);
-
-  if (INTENSITY (color[0], color[1], color[2]) > 0.5)
-    cairo_set_source_rgb (cr, 0., 0., 0.);
-  else
-    cairo_set_source_rgb (cr, 1., 1., 1.);
-
-  cairo_set_line_width (cr, *focus_width);
-
-  if (dash_list[0])
-    {
-      gint n_dashes = strlen ((gchar *)dash_list);
-      gdouble *dashes = g_new (gdouble, n_dashes);
-      gdouble total_length = 0;
-      gdouble dash_offset;
-      gint i;
-
-      for (i = 0; i < n_dashes; i++)
-        {
-          dashes[i] = dash_list[i];
-          total_length += dash_list[i];
-        }
-
-      /* The dash offset here aligns the pattern to integer pixels
-       * by starting the dash at the right side of the left border
-       * Negative dash offsets in cairo don't work
-       * (https://bugs.freedesktop.org/show_bug.cgi?id=2729)
-       */
-      dash_offset = - *focus_width / 2.;
-      while (dash_offset < 0)
-        dash_offset += total_length;
-
-      cairo_set_dash (cr, dashes, n_dashes, dash_offset);
-      g_free (dashes);
-    }
-
-  g_free (dash_list);
-}
-
-static void
-palette_drag_begin (GtkWidget      *widget,
-                    GdkDragContext *context,
-                    gpointer        data)
-{
-  gdouble colors[4];
-
-  palette_get_color (widget, colors);
-  set_color_icon (context, colors);
-}
-
-static void
-palette_drag_handle (GtkWidget        *widget,
-                     GdkDragContext   *context,
-                     GtkSelectionData *selection_data,
-                     guint             info,
-                     guint             time,
-                     gpointer          data)
-{
-  guint16 vals[4];
-  gdouble colsrc[4];
-
-  palette_get_color (widget, colsrc);
-
-  vals[0] = colsrc[COLORSEL_RED] * 0xffff;
-  vals[1] = colsrc[COLORSEL_GREEN] * 0xffff;
-  vals[2] = colsrc[COLORSEL_BLUE] * 0xffff;
-  vals[3] = 0xffff;
-
-  gtk_selection_data_set (selection_data,
-                          gdk_atom_intern_static_string ("application/x-color"),
-                          16, (guchar *)vals, 8);
-}
-
-static void
-palette_drag_end (GtkWidget      *widget,
-                  GdkDragContext *context,
-                  gpointer        data)
-{
-  g_object_set_data (G_OBJECT (widget), I_("gtk-color-selection-drag-window"), NULL);
-}
-
-static GdkColor *
-get_current_colors (GtkColorSelection *colorsel)
-{
-  GtkSettings *settings;
-  GdkColor *colors = NULL;
-  gint n_colors = 0;
-  gchar *palette;
-
-  settings = gtk_widget_get_settings (GTK_WIDGET (colorsel));
-  g_object_get (settings, "gtk-color-palette", &palette, NULL);
-
-  if (!gtk_color_selection_palette_from_string (palette, &colors, &n_colors))
-    {
-      gtk_color_selection_palette_from_string (DEFAULT_COLOR_PALETTE,
-                                               &colors,
-                                               &n_colors);
-    }
-  else
-    {
-      /* If there are less colors provided than the number of slots in the
-       * color selection, we fill in the rest from the defaults.
-       */
-      if (n_colors < (GTK_CUSTOM_PALETTE_WIDTH * GTK_CUSTOM_PALETTE_HEIGHT))
-        {
-          GdkColor *tmp_colors = colors;
-          gint tmp_n_colors = n_colors;
-
-          gtk_color_selection_palette_from_string (DEFAULT_COLOR_PALETTE,
-                                                   &colors,
-                                                   &n_colors);
-          memcpy (colors, tmp_colors, sizeof (GdkColor) * tmp_n_colors);
-
-          g_free (tmp_colors);
-        }
-    }
-
-  /* make sure that we fill every slot */
-  g_assert (n_colors == GTK_CUSTOM_PALETTE_WIDTH * GTK_CUSTOM_PALETTE_HEIGHT);
-  g_free (palette);
-
-  return colors;
-}
-
-/* Changes the model color */
-static void
-palette_change_color (GtkWidget         *drawing_area,
-                      GtkColorSelection *colorsel,
-                      gdouble           *color)
-{
-  gint x, y;
-  GtkColorSelectionPrivate *priv;
-  GdkColor gdk_color;
-  GdkColor *current_colors;
-  GdkScreen *screen;
-
-  g_return_if_fail (GTK_IS_COLOR_SELECTION (colorsel));
-  g_return_if_fail (GTK_IS_DRAWING_AREA (drawing_area));
-
-  priv = colorsel->private_data;
-
-  gdk_color.red = UNSCALE (color[0]);
-  gdk_color.green = UNSCALE (color[1]);
-  gdk_color.blue = UNSCALE (color[2]);
-  gdk_color.pixel = 0;
-
-  x = 0;
-  y = 0;                        /* Quiet GCC */
-  while (x < GTK_CUSTOM_PALETTE_WIDTH)
-    {
-      y = 0;
-      while (y < GTK_CUSTOM_PALETTE_HEIGHT)
-        {
-          if (priv->custom_palette[x][y] == drawing_area)
-            goto out;
-
-          ++y;
-        }
-
-      ++x;
-    }
-
- out:
-
-  g_assert (x < GTK_CUSTOM_PALETTE_WIDTH || y < GTK_CUSTOM_PALETTE_HEIGHT);
-
-  current_colors = get_current_colors (colorsel);
-  current_colors[y * GTK_CUSTOM_PALETTE_WIDTH + x] = gdk_color;
-
-  screen = gtk_widget_get_screen (GTK_WIDGET (colorsel));
-  if (change_palette_hook != default_change_palette_func)
-    (* change_palette_hook) (screen, current_colors,
-                             GTK_CUSTOM_PALETTE_WIDTH * GTK_CUSTOM_PALETTE_HEIGHT);
-  else if (noscreen_change_palette_hook != default_noscreen_change_palette_func)
-    {
-      if (screen != gdk_screen_get_default ())
-        g_warning ("gtk_color_selection_set_change_palette_hook used by "
-                   "widget is not on the default screen.");
-      (* noscreen_change_palette_hook) (current_colors,
-                                        GTK_CUSTOM_PALETTE_WIDTH * GTK_CUSTOM_PALETTE_HEIGHT);
-    }
-  else
-    (* change_palette_hook) (screen, current_colors,
-                             GTK_CUSTOM_PALETTE_WIDTH * GTK_CUSTOM_PALETTE_HEIGHT);
-
-  g_free (current_colors);
-}
-
-/* Changes the view color */
-static void
-palette_set_color (GtkWidget         *drawing_area,
-                   GtkColorSelection *colorsel,
-                   gdouble           *color)
-{
-  gdouble *new_color = g_new (double, 4);
-  GdkRGBA rgba;
-
-  rgba.red = color[0];
-  rgba.green = color[1];
-  rgba.blue = color[2];
-  rgba.alpha = 1;
-
-  gtk_widget_override_background_color (drawing_area, GTK_STATE_FLAG_NORMAL, &rgba);
-
-  if (GPOINTER_TO_INT (g_object_get_data (G_OBJECT (drawing_area), "color_set")) == 0)
-    {
-      static const GtkTargetEntry targets[] = {
-        { "application/x-color", 0 }
-      };
-      gtk_drag_source_set (drawing_area,
-                           GDK_BUTTON1_MASK | GDK_BUTTON3_MASK,
-                           targets, 1,
-                           GDK_ACTION_COPY | GDK_ACTION_MOVE);
-
-      g_signal_connect (drawing_area, "drag-begin",
-                        G_CALLBACK (palette_drag_begin),
-                        colorsel);
-      g_signal_connect (drawing_area, "drag-data-get",
-                        G_CALLBACK (palette_drag_handle),
-                        colorsel);
-
-      g_object_set_data (G_OBJECT (drawing_area), I_("color_set"),
-                         GINT_TO_POINTER (1));
-    }
-
-  new_color[0] = color[0];
-  new_color[1] = color[1];
-  new_color[2] = color[2];
-  new_color[3] = 1.0;
-
-  g_object_set_data_full (G_OBJECT (drawing_area),
-                          I_("color_val"), new_color, (GDestroyNotify)g_free);
-}
-
-static void
-popup_position_func (GtkMenu   *menu,
-                     gint      *x,
-                     gint      *y,
-                     gboolean  *push_in,
-                     gpointer   user_data)
-{
-  GtkAllocation allocation;
-  GtkWidget *widget;
-  GtkRequisition req;
-  gint root_x, root_y;
-  GdkScreen *screen;
-
-  widget = GTK_WIDGET (user_data);
-
-  g_return_if_fail (gtk_widget_get_realized (widget));
-
-  gdk_window_get_origin (gtk_widget_get_window (widget),
-                         &root_x, &root_y);
-
-  gtk_widget_get_preferred_size (GTK_WIDGET (menu),
-                                 &req, NULL);
-  gtk_widget_get_allocation (widget, &allocation);
-
-  /* Put corner of menu centered on color cell */
-  *x = root_x + allocation.width / 2;
-  *y = root_y + allocation.height / 2;
-
-  /* Ensure sanity */
-  screen = gtk_widget_get_screen (widget);
-  *x = CLAMP (*x, 0, MAX (0, gdk_screen_get_width (screen) - req.width));
-  *y = CLAMP (*y, 0, MAX (0, gdk_screen_get_height (screen) - req.height));
-}
-
-static void
-save_color_selected (GtkWidget *menuitem,
-                     gpointer   data)
-{
-  GtkColorSelection *colorsel;
-  GtkWidget *drawing_area;
-  GtkColorSelectionPrivate *priv;
-
-  drawing_area = GTK_WIDGET (data);
-
-  colorsel = GTK_COLOR_SELECTION (g_object_get_data (G_OBJECT (drawing_area),
-                                                     "gtk-color-sel"));
-
-  priv = colorsel->private_data;
-
-  palette_change_color (drawing_area, colorsel, priv->color);
-}
-
-static void
-do_popup (GtkColorSelection *colorsel,
-          GtkWidget         *drawing_area,
-          guint32            timestamp)
-{
-  GtkWidget *menu;
-  GtkWidget *mi;
-
-  g_object_set_data (G_OBJECT (drawing_area),
-                     I_("gtk-color-sel"),
-                     colorsel);
-
-  menu = gtk_menu_new ();
-
-  mi = gtk_menu_item_new_with_mnemonic (_("_Save color here"));
-
-  g_signal_connect (mi, "activate",
-                    G_CALLBACK (save_color_selected),
-                    drawing_area);
-
-  gtk_menu_shell_append (GTK_MENU_SHELL (menu), mi);
-
-  gtk_widget_show_all (mi);
-
-  gtk_menu_popup (GTK_MENU (menu), NULL, NULL,
-                  popup_position_func, drawing_area,
-                  3, timestamp);
-}
-
-
-static gboolean
-palette_enter (GtkWidget        *drawing_area,
-               GdkEventCrossing *event,
-               gpointer        data)
-{
-  g_object_set_data (G_OBJECT (drawing_area),
-                     I_("gtk-colorsel-have-pointer"),
-                     GUINT_TO_POINTER (TRUE));
-
-  return FALSE;
-}
-
-static gboolean
-palette_leave (GtkWidget        *drawing_area,
-               GdkEventCrossing *event,
-               gpointer        data)
-{
-  g_object_set_data (G_OBJECT (drawing_area),
-                     I_("gtk-colorsel-have-pointer"),
-                     NULL);
-
-  return FALSE;
-}
-
-static gboolean
-palette_press (GtkWidget      *drawing_area,
-               GdkEventButton *event,
-               gpointer        data)
-{
-  GtkColorSelection *colorsel = GTK_COLOR_SELECTION (data);
-
-  gtk_widget_grab_focus (drawing_area);
-
-  if (gdk_event_triggers_context_menu ((GdkEvent *) event))
-    {
-      do_popup (colorsel, drawing_area, event->time);
-      return TRUE;
-    }
-
-  return FALSE;
-}
-
-static gboolean
-palette_release (GtkWidget      *drawing_area,
-                 GdkEventButton *event,
-                 gpointer        data)
-{
-  GtkColorSelection *colorsel = GTK_COLOR_SELECTION (data);
-
-  gtk_widget_grab_focus (drawing_area);
-
-  if (event->button == GDK_BUTTON_PRIMARY &&
-      g_object_get_data (G_OBJECT (drawing_area),
-                         "gtk-colorsel-have-pointer") != NULL)
-    {
-      if (GPOINTER_TO_INT (g_object_get_data (G_OBJECT (drawing_area), "color_set")) != 0)
-        {
-          gdouble color[4];
-          palette_get_color (drawing_area, color);
-          set_color_internal (colorsel, color);
-        }
-    }
-
-  return FALSE;
-}
-
-static void
-palette_drop_handle (GtkWidget        *widget,
-                     GdkDragContext   *context,
-                     gint              x,
-                     gint              y,
-                     GtkSelectionData *selection_data,
-                     guint             info,
-                     guint             time,
-                     gpointer          data)
-{
-  GtkColorSelection *colorsel = GTK_COLOR_SELECTION (data);
-  gint length;
-  guint16 *vals;
-  gdouble color[4];
-
-  length = gtk_selection_data_get_length (selection_data);
-
-  if (length < 0)
-    return;
-
-  /* We accept drops with the wrong format, since the KDE color
-   * chooser incorrectly drops application/x-color with format 8.
-   */
-  if (length != 8)
-    {
-      g_warning ("Received invalid color data\n");
-      return;
-    }
-
-  vals = (guint16 *) gtk_selection_data_get_data (selection_data);
-
-  color[0] = (gdouble)vals[0] / 0xffff;
-  color[1] = (gdouble)vals[1] / 0xffff;
-  color[2] = (gdouble)vals[2] / 0xffff;
-  color[3] = (gdouble)vals[3] / 0xffff;
-  palette_change_color (widget, colorsel, color);
-  set_color_internal (colorsel, color);
-}
-
-static gint
-palette_activate (GtkWidget   *widget,
-                  GdkEventKey *event,
-                  gpointer     data)
-{
-  /* should have a drawing area subclass with an activate signal */
-  if ((event->keyval == GDK_KEY_space) ||
-      (event->keyval == GDK_KEY_Return) ||
-      (event->keyval == GDK_KEY_ISO_Enter) ||
-      (event->keyval == GDK_KEY_KP_Enter) ||
-      (event->keyval == GDK_KEY_KP_Space))
-    {
-      if (GPOINTER_TO_INT (g_object_get_data (G_OBJECT (widget), "color_set")) != 0)
-        {
-          gdouble color[4];
-          palette_get_color (widget, color);
-          set_color_internal (GTK_COLOR_SELECTION (data), color);
-        }
-      return TRUE;
-    }
-
-  return FALSE;
-}
-
-static gboolean
-palette_popup (GtkWidget *widget,
-               gpointer   data)
-{
-  GtkColorSelection *colorsel = GTK_COLOR_SELECTION (data);
-
-  do_popup (colorsel, widget, GDK_CURRENT_TIME);
-  return TRUE;
-}
-
-
-static GtkWidget*
-palette_new (GtkColorSelection *colorsel)
-{
-  GtkWidget *retval;
-
-  static const GtkTargetEntry targets[] = {
-    { "application/x-color", 0 }
-  };
-
-  retval = gtk_drawing_area_new ();
-
-  gtk_widget_set_can_focus (retval, TRUE);
-
-  g_object_set_data (G_OBJECT (retval), I_("color_set"), GINT_TO_POINTER (0));
-  gtk_widget_set_events (retval, GDK_BUTTON_PRESS_MASK
-                         | GDK_BUTTON_RELEASE_MASK
-                         | GDK_EXPOSURE_MASK
-                         | GDK_ENTER_NOTIFY_MASK
-                         | GDK_LEAVE_NOTIFY_MASK);
-
-  g_signal_connect (retval, "draw",
-                    G_CALLBACK (palette_draw), colorsel);
-  g_signal_connect (retval, "button-press-event",
-                    G_CALLBACK (palette_press), colorsel);
-  g_signal_connect (retval, "button-release-event",
-                    G_CALLBACK (palette_release), colorsel);
-  g_signal_connect (retval, "enter-notify-event",
-                    G_CALLBACK (palette_enter), colorsel);
-  g_signal_connect (retval, "leave-notify-event",
-                    G_CALLBACK (palette_leave), colorsel);
-  g_signal_connect (retval, "key-press-event",
-                    G_CALLBACK (palette_activate), colorsel);
-  g_signal_connect (retval, "popup-menu",
-                    G_CALLBACK (palette_popup), colorsel);
-
-  gtk_drag_dest_set (retval,
-                     GTK_DEST_DEFAULT_HIGHLIGHT |
-                     GTK_DEST_DEFAULT_MOTION |
-                     GTK_DEST_DEFAULT_DROP,
-                     targets, 1,
-                     GDK_ACTION_COPY);
-
-  g_signal_connect (retval, "drag-end",
-                    G_CALLBACK (palette_drag_end), NULL);
-  g_signal_connect (retval, "drag-data-received",
-                    G_CALLBACK (palette_drop_handle), colorsel);
-
-  gtk_widget_set_tooltip_text (retval,
-    _("Click this palette entry to make it the current color. "
-      "To change this entry, drag a color swatch here or right-click "
-      "it and select \"Save color here.\""));
-  return retval;
-}
-
-
-/* The actual GtkColorSelection widget */
-
-static GdkCursor *
-make_picker_cursor (GdkScreen *screen)
-{
-  GdkCursor *cursor;
-
-  cursor = gdk_cursor_new_from_name (gdk_screen_get_display (screen),
-                                     "color-picker");
-
-  if (!cursor)
-    {
-      GdkPixbuf *pixbuf;
-
-      pixbuf = gdk_pixbuf_new_from_data (dropper_bits,
-                                         GDK_COLORSPACE_RGB, TRUE, 8,
-                                         DROPPER_WIDTH, DROPPER_HEIGHT,
-                                         DROPPER_STRIDE,
-                                         NULL, NULL);
-
-      cursor = gdk_cursor_new_from_pixbuf (gdk_screen_get_display (screen),
-                                           pixbuf,
-                                           DROPPER_X_HOT, DROPPER_Y_HOT);
-
-      g_object_unref (pixbuf);
-    }
-
-  return cursor;
-}
-
-static void
-grab_color_at_pointer (GdkScreen *screen,
-                       GdkDevice *device,
-                       gint       x_root,
-                       gint       y_root,
-                       gpointer   data)
-{
-  GdkPixbuf *pixbuf;
-  guchar *pixels;
-  GtkColorSelection *colorsel = data;
-  GtkColorSelectionPrivate *priv;
-  GdkColor color;
-  GdkWindow *root_window = gdk_screen_get_root_window (screen);
-
-  priv = colorsel->private_data;
-
-  pixbuf = gdk_pixbuf_get_from_window (root_window,
-                                       x_root, y_root,
-                                       1, 1);
-  if (!pixbuf)
-    {
-      gint x, y;
-      GdkWindow *window = gdk_device_get_window_at_position (device, &x, &y);
-      if (!window)
-        return;
-      pixbuf = gdk_pixbuf_get_from_window (window,
-                                           x, y,
-                                           1, 1);
-      if (!pixbuf)
-        return;
-    }
-  pixels = gdk_pixbuf_get_pixels (pixbuf);
-  color.red = pixels[0] * 0x101;
-  color.green = pixels[1] * 0x101;
-  color.blue = pixels[2] * 0x101;
-  g_object_unref (pixbuf);
-
-  priv->color[COLORSEL_RED] = SCALE (color.red);
-  priv->color[COLORSEL_GREEN] = SCALE (color.green);
-  priv->color[COLORSEL_BLUE] = SCALE (color.blue);
-
-  gtk_rgb_to_hsv (priv->color[COLORSEL_RED],
-                  priv->color[COLORSEL_GREEN],
-                  priv->color[COLORSEL_BLUE],
-                  &priv->color[COLORSEL_HUE],
-                  &priv->color[COLORSEL_SATURATION],
-                  &priv->color[COLORSEL_VALUE]);
-
-  update_color (colorsel);
-}
-
-static void
-shutdown_eyedropper (GtkWidget *widget)
-{
-  GtkColorSelection *colorsel;
-  GtkColorSelectionPrivate *priv;
-
-  colorsel = GTK_COLOR_SELECTION (widget);
-  priv = colorsel->private_data;
-
-  if (priv->has_grab)
-    {
-      gdk_device_ungrab (priv->keyboard_device, priv->grab_time);
-      gdk_device_ungrab (priv->pointer_device, priv->grab_time);
-      gtk_device_grab_remove (priv->dropper_grab_widget, priv->pointer_device);
-
-      priv->has_grab = FALSE;
-      priv->keyboard_device = NULL;
-      priv->pointer_device = NULL;
-    }
-}
-
-static void
-mouse_motion (GtkWidget      *invisible,
-              GdkEventMotion *event,
-              gpointer        data)
-{
-  grab_color_at_pointer (gdk_event_get_screen ((GdkEvent *) event),
-                         gdk_event_get_device ((GdkEvent *) event),
-                         event->x_root, event->y_root, data);
-}
-
-static gboolean
-mouse_release (GtkWidget      *invisible,
-               GdkEventButton *event,
-               gpointer        data)
-{
-  /* GtkColorSelection *colorsel = data; */
-
-  if (event->button != GDK_BUTTON_PRIMARY)
-    return FALSE;
-
-  grab_color_at_pointer (gdk_event_get_screen ((GdkEvent *) event),
-                         gdk_event_get_device ((GdkEvent *) event),
-                         event->x_root, event->y_root, data);
-
-  shutdown_eyedropper (GTK_WIDGET (data));
-
-  g_signal_handlers_disconnect_by_func (invisible,
-                                        mouse_motion,
-                                        data);
-  g_signal_handlers_disconnect_by_func (invisible,
-                                        mouse_release,
-                                        data);
-
-  return TRUE;
-}
-
-/* Helper Functions */
-
-static gboolean
-key_press (GtkWidget   *invisible,
-           GdkEventKey *event,
-           gpointer     data)
-{
-  GdkScreen *screen = gdk_event_get_screen ((GdkEvent *) event);
-  GdkDevice *device, *pointer_device;
-  guint state = event->state & gtk_accelerator_get_default_mod_mask ();
-  gint x, y;
-  gint dx, dy;
-
-  device = gdk_event_get_device ((GdkEvent * ) event);
-  pointer_device = gdk_device_get_associated_device (device);
-  gdk_device_get_position (pointer_device, NULL, &x, &y);
-
-  dx = 0;
-  dy = 0;
-
-  switch (event->keyval)
-    {
-    case GDK_KEY_space:
-    case GDK_KEY_Return:
-    case GDK_KEY_ISO_Enter:
-    case GDK_KEY_KP_Enter:
-    case GDK_KEY_KP_Space:
-      grab_color_at_pointer (screen, pointer_device, x, y, data);
-      /* fall through */
-
-    case GDK_KEY_Escape:
-      shutdown_eyedropper (data);
-
-      g_signal_handlers_disconnect_by_func (invisible,
-                                            mouse_press,
-                                            data);
-      g_signal_handlers_disconnect_by_func (invisible,
-                                            key_press,
-                                            data);
-
-      return TRUE;
-
-    case GDK_KEY_Up:
-    case GDK_KEY_KP_Up:
-      dy = state == GDK_MOD1_MASK ? -BIG_STEP : -1;
-      break;
-
-    case GDK_KEY_Down:
-    case GDK_KEY_KP_Down:
-      dy = state == GDK_MOD1_MASK ? BIG_STEP : 1;
-      break;
-
-    case GDK_KEY_Left:
-    case GDK_KEY_KP_Left:
-      dx = state == GDK_MOD1_MASK ? -BIG_STEP : -1;
-      break;
-
-    case GDK_KEY_Right:
-    case GDK_KEY_KP_Right:
-      dx = state == GDK_MOD1_MASK ? BIG_STEP : 1;
-      break;
-
-    default:
-      return FALSE;
-    }
-
-  gdk_device_warp (pointer_device, screen, x + dx, y + dy);
-
-  return TRUE;
-
-}
-
-static gboolean
-mouse_press (GtkWidget      *invisible,
-             GdkEventButton *event,
-             gpointer        data)
-{
-  if (event->type == GDK_BUTTON_PRESS && event->button == GDK_BUTTON_PRIMARY)
-    {
-      g_signal_connect (invisible, "motion-notify-event",
-                        G_CALLBACK (mouse_motion), data);
-      g_signal_connect (invisible, "button-release-event",
-                        G_CALLBACK (mouse_release), data);
-      g_signal_handlers_disconnect_by_func (invisible,
-                                            mouse_press,
-                                            data);
-      g_signal_handlers_disconnect_by_func (invisible,
-                                            key_press,
-                                            data);
-      return TRUE;
-    }
-
-  return FALSE;
-}
-
-/* when the button is clicked */
-static void
-get_screen_color (GtkWidget *button)
-{
-  GtkColorSelection *colorsel = g_object_get_data (G_OBJECT (button), "COLORSEL");
-  GtkColorSelectionPrivate *priv = colorsel->private_data;
-  GdkScreen *screen = gtk_widget_get_screen (GTK_WIDGET (button));
-  GdkDevice *device, *keyb_device, *pointer_device;
-  GdkCursor *picker_cursor;
-  GdkGrabStatus grab_status;
-  GdkWindow *window;
-  GtkWidget *grab_widget, *toplevel;
-
-  guint32 time = gtk_get_current_event_time ();
-
-  device = gtk_get_current_event_device ();
-
-  if (gdk_device_get_source (device) == GDK_SOURCE_KEYBOARD)
-    {
-      keyb_device = device;
-      pointer_device = gdk_device_get_associated_device (device);
-    }
-  else
-    {
-      pointer_device = device;
-      keyb_device = gdk_device_get_associated_device (device);
-    }
-
-  if (priv->dropper_grab_widget == NULL)
-    {
-      grab_widget = gtk_window_new (GTK_WINDOW_POPUP);
-      gtk_window_set_screen (GTK_WINDOW (grab_widget), screen);
-      gtk_window_resize (GTK_WINDOW (grab_widget), 1, 1);
-      gtk_window_move (GTK_WINDOW (grab_widget), -100, -100);
-      gtk_widget_show (grab_widget);
-
-      gtk_widget_add_events (grab_widget,
-                             GDK_BUTTON_RELEASE_MASK | GDK_BUTTON_PRESS_MASK | GDK_POINTER_MOTION_MASK);
-
-      toplevel = gtk_widget_get_toplevel (GTK_WIDGET (colorsel));
-
-      if (GTK_IS_WINDOW (toplevel))
-        {
-          if (gtk_window_has_group (GTK_WINDOW (toplevel)))
-            gtk_window_group_add_window (gtk_window_get_group (GTK_WINDOW (toplevel)),
-                                         GTK_WINDOW (grab_widget));
-        }
-
-      priv->dropper_grab_widget = grab_widget;
-    }
-
-  window = gtk_widget_get_window (priv->dropper_grab_widget);
-
-  if (gdk_device_grab (keyb_device,
-                       window,
-                       GDK_OWNERSHIP_APPLICATION, FALSE,
-                       GDK_KEY_PRESS_MASK | GDK_KEY_RELEASE_MASK,
-                       NULL, time) != GDK_GRAB_SUCCESS)
-    return;
-
-  picker_cursor = make_picker_cursor (screen);
-  grab_status = gdk_device_grab (pointer_device,
-                                 window,
-                                 GDK_OWNERSHIP_APPLICATION,
-                                 FALSE,
-                                 GDK_BUTTON_RELEASE_MASK | GDK_BUTTON_PRESS_MASK | GDK_POINTER_MOTION_MASK,
-                                 picker_cursor,
-                                 time);
-  g_object_unref (picker_cursor);
-
-  if (grab_status != GDK_GRAB_SUCCESS)
-    {
-      gdk_device_ungrab (keyb_device, time);
-      return;
-    }
-
-  gtk_device_grab_add (priv->dropper_grab_widget,
-                       pointer_device,
-                       TRUE);
-
-  priv->grab_time = time;
-  priv->has_grab = TRUE;
-  priv->keyboard_device = keyb_device;
-  priv->pointer_device = pointer_device;
-
-  g_signal_connect (priv->dropper_grab_widget, "button-press-event",
-                    G_CALLBACK (mouse_press), colorsel);
-  g_signal_connect (priv->dropper_grab_widget, "key-press-event",
-                    G_CALLBACK (key_press), colorsel);
-}
-
-static void
-hex_changed (GtkWidget *hex_entry,
-             gpointer   data)
-{
-  GtkColorSelection *colorsel;
-  GtkColorSelectionPrivate *priv;
-  GdkRGBA color;
-  gchar *text;
-
-  colorsel = GTK_COLOR_SELECTION (data);
-  priv = colorsel->private_data;
-
-  if (priv->changing)
-    return;
-
-  text = gtk_editable_get_chars (GTK_EDITABLE (priv->hex_entry), 0, -1);
-  if (gdk_rgba_parse (&color, text))
-    {
-      priv->color[COLORSEL_RED]   = color.red;
-      priv->color[COLORSEL_GREEN] = color.green;
-      priv->color[COLORSEL_BLUE]  = color.blue;
-      gtk_rgb_to_hsv (priv->color[COLORSEL_RED],
-                      priv->color[COLORSEL_GREEN],
-                      priv->color[COLORSEL_BLUE],
-                      &priv->color[COLORSEL_HUE],
-                      &priv->color[COLORSEL_SATURATION],
-                      &priv->color[COLORSEL_VALUE]);
-      update_color (colorsel);
-    }
-  g_free (text);
-}
-
-static gboolean
-hex_focus_out (GtkWidget     *hex_entry,
-               GdkEventFocus *event,
-               gpointer       data)
-{
-  hex_changed (hex_entry, data);
-
-  return FALSE;
-}
-
-static void
-hsv_changed (GtkWidget *hsv,
-             gpointer   data)
-{
-  GtkColorSelection *colorsel;
-  GtkColorSelectionPrivate *priv;
-
-  colorsel = GTK_COLOR_SELECTION (data);
-  priv = colorsel->private_data;
-
-  if (priv->changing)
-    return;
-
-  gtk_hsv_get_color (GTK_HSV (hsv),
-                     &priv->color[COLORSEL_HUE],
-                     &priv->color[COLORSEL_SATURATION],
-                     &priv->color[COLORSEL_VALUE]);
-  gtk_hsv_to_rgb (priv->color[COLORSEL_HUE],
-                  priv->color[COLORSEL_SATURATION],
-                  priv->color[COLORSEL_VALUE],
-                  &priv->color[COLORSEL_RED],
-                  &priv->color[COLORSEL_GREEN],
-                  &priv->color[COLORSEL_BLUE]);
-  update_color (colorsel);
-}
-
-static void
-adjustment_changed (GtkAdjustment *adjustment,
-                    gpointer       data)
-{
-  GtkColorSelection *colorsel;
-  GtkColorSelectionPrivate *priv;
-
-  colorsel = GTK_COLOR_SELECTION (g_object_get_data (G_OBJECT (adjustment), "COLORSEL"));
-  priv = colorsel->private_data;
-
-  if (priv->changing)
-    return;
-
-  switch (GPOINTER_TO_INT (data))
-    {
-    case COLORSEL_SATURATION:
-    case COLORSEL_VALUE:
-      priv->color[GPOINTER_TO_INT (data)] = gtk_adjustment_get_value (adjustment) / 100;
-      gtk_hsv_to_rgb (priv->color[COLORSEL_HUE],
-                      priv->color[COLORSEL_SATURATION],
-                      priv->color[COLORSEL_VALUE],
-                      &priv->color[COLORSEL_RED],
-                      &priv->color[COLORSEL_GREEN],
-                      &priv->color[COLORSEL_BLUE]);
-      break;
-    case COLORSEL_HUE:
-      priv->color[GPOINTER_TO_INT (data)] = gtk_adjustment_get_value (adjustment) / 360;
-      gtk_hsv_to_rgb (priv->color[COLORSEL_HUE],
-                      priv->color[COLORSEL_SATURATION],
-                      priv->color[COLORSEL_VALUE],
-                      &priv->color[COLORSEL_RED],
-                      &priv->color[COLORSEL_GREEN],
-                      &priv->color[COLORSEL_BLUE]);
-      break;
-    case COLORSEL_RED:
-    case COLORSEL_GREEN:
-    case COLORSEL_BLUE:
-      priv->color[GPOINTER_TO_INT (data)] = gtk_adjustment_get_value (adjustment) / 255;
-
-      gtk_rgb_to_hsv (priv->color[COLORSEL_RED],
-                      priv->color[COLORSEL_GREEN],
-                      priv->color[COLORSEL_BLUE],
-                      &priv->color[COLORSEL_HUE],
-                      &priv->color[COLORSEL_SATURATION],
-                      &priv->color[COLORSEL_VALUE]);
-      break;
-    default:
-      priv->color[GPOINTER_TO_INT (data)] = gtk_adjustment_get_value (adjustment) / 255;
-      break;
-    }
-  update_color (colorsel);
-}
-
-static void
-opacity_entry_changed (GtkWidget *opacity_entry,
-                       gpointer   data)
-{
-  GtkColorSelection *colorsel;
-  GtkColorSelectionPrivate *priv;
-  GtkAdjustment *adj;
-  gchar *text;
-
-  colorsel = GTK_COLOR_SELECTION (data);
-  priv = colorsel->private_data;
-
-  if (priv->changing)
-    return;
-
-  text = gtk_editable_get_chars (GTK_EDITABLE (priv->opacity_entry), 0, -1);
-  adj = gtk_range_get_adjustment (GTK_RANGE (priv->opacity_slider));
-  gtk_adjustment_set_value (adj, g_strtod (text, NULL));
-
-  update_color (colorsel);
-
-  g_free (text);
-}
-
-static void
-make_label_spinbutton (GtkColorSelection *colorsel,
-                       GtkWidget        **spinbutton,
-                       gchar             *text,
-                       GtkWidget         *table,
-                       gint               i,
-                       gint               j,
-                       gint               channel_type,
-                       const gchar       *tooltip)
-{
-  GtkWidget *label;
-  GtkAdjustment *adjust;
-
-  if (channel_type == COLORSEL_HUE)
-    {
-      adjust = gtk_adjustment_new (0.0, 0.0, 360.0, 1.0, 1.0, 0.0);
-    }
-  else if (channel_type == COLORSEL_SATURATION ||
-           channel_type == COLORSEL_VALUE)
-    {
-      adjust = gtk_adjustment_new (0.0, 0.0, 100.0, 1.0, 1.0, 0.0);
-    }
-  else
-    {
-      adjust = gtk_adjustment_new (0.0, 0.0, 255.0, 1.0, 1.0, 0.0);
-    }
-  g_object_set_data (G_OBJECT (adjust), I_("COLORSEL"), colorsel);
-  *spinbutton = gtk_spin_button_new (adjust, 10.0, 0);
-
-  gtk_widget_set_tooltip_text (*spinbutton, tooltip);
-
-  g_signal_connect (adjust, "value-changed",
-                    G_CALLBACK (adjustment_changed),
-                    GINT_TO_POINTER (channel_type));
-  label = gtk_label_new_with_mnemonic (text);
-  gtk_label_set_mnemonic_widget (GTK_LABEL (label), *spinbutton);
-
-  gtk_widget_set_halign (label, GTK_ALIGN_START);
-  gtk_widget_set_valign (label, GTK_ALIGN_CENTER);
-  gtk_grid_attach (GTK_GRID (table), label, i, j, 1, 1);
-  gtk_grid_attach (GTK_GRID (table), *spinbutton, i+1, j, 1, 1);
-}
-
-static void
-make_palette_frame (GtkColorSelection *colorsel,
-                    GtkWidget         *table,
-                    gint               i,
-                    gint               j)
-{
-  GtkWidget *frame;
-  GtkColorSelectionPrivate *priv;
-
-  priv = colorsel->private_data;
-  frame = gtk_frame_new (NULL);
-  gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_IN);
-  priv->custom_palette[i][j] = palette_new (colorsel);
-  gtk_widget_set_size_request (priv->custom_palette[i][j], CUSTOM_PALETTE_ENTRY_WIDTH, CUSTOM_PALETTE_ENTRY_HEIGHT);
-  gtk_container_add (GTK_CONTAINER (frame), priv->custom_palette[i][j]);
-  gtk_grid_attach (GTK_GRID (table), frame, i, j, 1, 1);
-}
-
-/* Set the palette entry [x][y] to be the currently selected one. */
-static void
-set_selected_palette (GtkColorSelection *colorsel, int x, int y)
-{
-  GtkColorSelectionPrivate *priv = colorsel->private_data;
-
-  gtk_widget_grab_focus (priv->custom_palette[x][y]);
-}
-
-static double
-scale_round (double val, double factor)
-{
-  val = floor (val * factor + 0.5);
-  val = MAX (val, 0);
-  val = MIN (val, factor);
-  return val;
-}
-
-static void
-update_color (GtkColorSelection *colorsel)
-{
-  GtkColorSelectionPrivate *priv = colorsel->private_data;
-  gchar entryval[12];
-  gchar opacity_text[32];
-  gchar *ptr;
-
-  priv->changing = TRUE;
-  color_sample_update_samples (colorsel);
-
-  gtk_hsv_set_color (GTK_HSV (priv->triangle_colorsel),
-                     priv->color[COLORSEL_HUE],
-                     priv->color[COLORSEL_SATURATION],
-                     priv->color[COLORSEL_VALUE]);
-  gtk_adjustment_set_value (gtk_spin_button_get_adjustment
-                            (GTK_SPIN_BUTTON (priv->hue_spinbutton)),
-                            scale_round (priv->color[COLORSEL_HUE], 360));
-  gtk_adjustment_set_value (gtk_spin_button_get_adjustment
-                            (GTK_SPIN_BUTTON (priv->sat_spinbutton)),
-                            scale_round (priv->color[COLORSEL_SATURATION], 100));
-  gtk_adjustment_set_value (gtk_spin_button_get_adjustment
-                            (GTK_SPIN_BUTTON (priv->val_spinbutton)),
-                            scale_round (priv->color[COLORSEL_VALUE], 100));
-  gtk_adjustment_set_value (gtk_spin_button_get_adjustment
-                            (GTK_SPIN_BUTTON (priv->red_spinbutton)),
-                            scale_round (priv->color[COLORSEL_RED], 255));
-  gtk_adjustment_set_value (gtk_spin_button_get_adjustment
-                            (GTK_SPIN_BUTTON (priv->green_spinbutton)),
-                            scale_round (priv->color[COLORSEL_GREEN], 255));
-  gtk_adjustment_set_value (gtk_spin_button_get_adjustment
-                            (GTK_SPIN_BUTTON (priv->blue_spinbutton)),
-                            scale_round (priv->color[COLORSEL_BLUE], 255));
-  gtk_adjustment_set_value (gtk_range_get_adjustment
-                            (GTK_RANGE (priv->opacity_slider)),
-                            scale_round (priv->color[COLORSEL_OPACITY], 255));
-
-  g_snprintf (opacity_text, 32, "%.0f", scale_round (priv->color[COLORSEL_OPACITY], 255));
-  gtk_entry_set_text (GTK_ENTRY (priv->opacity_entry), opacity_text);
-
-  g_snprintf (entryval, 11, "#%2X%2X%2X",
-              (guint) (scale_round (priv->color[COLORSEL_RED], 255)),
-              (guint) (scale_round (priv->color[COLORSEL_GREEN], 255)),
-              (guint) (scale_round (priv->color[COLORSEL_BLUE], 255)));
-
-  for (ptr = entryval; *ptr; ptr++)
-    if (*ptr == ' ')
-      *ptr = '0';
-  gtk_entry_set_text (GTK_ENTRY (priv->hex_entry), entryval);
-  priv->changing = FALSE;
-
-  g_object_ref (colorsel);
-
-  g_signal_emit (colorsel, color_selection_signals[COLOR_CHANGED], 0);
-
-  g_object_freeze_notify (G_OBJECT (colorsel));
-  g_object_notify (G_OBJECT (colorsel), "current-color");
-  g_object_notify (G_OBJECT (colorsel), "current-alpha");
-  g_object_thaw_notify (G_OBJECT (colorsel));
-
-  g_object_unref (colorsel);
-}
-
-static void
-update_palette (GtkColorSelection *colorsel)
-{
-  GdkColor *current_colors;
-  gint i, j;
-
-  current_colors = get_current_colors (colorsel);
-
-  for (i = 0; i < GTK_CUSTOM_PALETTE_HEIGHT; i++)
-    {
-      for (j = 0; j < GTK_CUSTOM_PALETTE_WIDTH; j++)
-        {
-          gint index;
-
-          index = i * GTK_CUSTOM_PALETTE_WIDTH + j;
-
-          gtk_color_selection_set_palette_color (colorsel,
-                                                 index,
-                                                 &current_colors[index]);
-        }
-    }
-
-  g_free (current_colors);
-}
-
-static void
-palette_change_notify_instance (GObject    *object,
-                                GParamSpec *pspec,
-                                gpointer    data)
-{
-  update_palette (GTK_COLOR_SELECTION (data));
-}
-
-static void
-default_noscreen_change_palette_func (const GdkColor *colors,
-                                      gint            n_colors)
-{
-  default_change_palette_func (gdk_screen_get_default (), colors, n_colors);
-}
-
-static void
-default_change_palette_func (GdkScreen      *screen,
-                             const GdkColor *colors,
-                             gint            n_colors)
-{
-  gchar *str;
-
-  str = gtk_color_selection_palette_to_string (colors, n_colors);
-
-  gtk_settings_set_string_property (gtk_settings_get_for_screen (screen),
-                                    "gtk-color-palette",
-                                    str,
-                                    "gtk_color_selection_palette_to_string");
-
-  g_free (str);
-}
-
-/**
- * gtk_color_selection_new:
- *
- * Creates a new GtkColorSelection.
- *
- * Return value: a new #GtkColorSelection
- */
-GtkWidget *
-gtk_color_selection_new (void)
-{
-  GtkColorSelection *colorsel;
-  GtkColorSelectionPrivate *priv;
-  gdouble color[4];
-  color[0] = 1.0;
-  color[1] = 1.0;
-  color[2] = 1.0;
-  color[3] = 1.0;
-
-  colorsel = g_object_new (GTK_TYPE_COLOR_SELECTION, NULL);
-  priv = colorsel->private_data;
-  set_color_internal (colorsel, color);
-  gtk_color_selection_set_has_opacity_control (colorsel, TRUE);
-
-  /* We want to make sure that default_set is FALSE.
-   * This way the user can still set it.
-   */
-  priv->default_set = FALSE;
-  priv->default_alpha_set = FALSE;
-
-  return GTK_WIDGET (colorsel);
-}
-
-/**
- * gtk_color_selection_get_has_opacity_control:
- * @colorsel: a #GtkColorSelection
- *
- * Determines whether the colorsel has an opacity control.
- *
- * Return value: %TRUE if the @colorsel has an opacity control,
- *     %FALSE if it does't
- */
-gboolean
-gtk_color_selection_get_has_opacity_control (GtkColorSelection *colorsel)
-{
-  GtkColorSelectionPrivate *priv;
-
-  g_return_val_if_fail (GTK_IS_COLOR_SELECTION (colorsel), FALSE);
-
-  priv = colorsel->private_data;
-
-  return priv->has_opacity;
-}
-
-/**
- * gtk_color_selection_set_has_opacity_control:
- * @colorsel: a #GtkColorSelection
- * @has_opacity: %TRUE if @colorsel can set the opacity, %FALSE otherwise
- *
- * Sets the @colorsel to use or not use opacity.
- */
-void
-gtk_color_selection_set_has_opacity_control (GtkColorSelection *colorsel,
-                                             gboolean           has_opacity)
-{
-  GtkColorSelectionPrivate *priv;
-
-  g_return_if_fail (GTK_IS_COLOR_SELECTION (colorsel));
-
-  priv = colorsel->private_data;
-  has_opacity = has_opacity != FALSE;
-
-  if (priv->has_opacity != has_opacity)
-    {
-      priv->has_opacity = has_opacity;
-      if (has_opacity)
-        {
-          gtk_widget_show (priv->opacity_slider);
-          gtk_widget_show (priv->opacity_label);
-          gtk_widget_show (priv->opacity_entry);
-        }
-      else
-        {
-          gtk_widget_hide (priv->opacity_slider);
-          gtk_widget_hide (priv->opacity_label);
-          gtk_widget_hide (priv->opacity_entry);
-        }
-      color_sample_update_samples (colorsel);
-
-      g_object_notify (G_OBJECT (colorsel), "has-opacity-control");
-    }
-}
-
-/**
- * gtk_color_selection_get_has_palette:
- * @colorsel: a #GtkColorSelection
- *
- * Determines whether the color selector has a color palette.
- *
- * Return value: %TRUE if the selector has a palette, %FALSE if it hasn't
- */
-gboolean
-gtk_color_selection_get_has_palette (GtkColorSelection *colorsel)
-{
-  GtkColorSelectionPrivate *priv;
-
-  g_return_val_if_fail (GTK_IS_COLOR_SELECTION (colorsel), FALSE);
-
-  priv = colorsel->private_data;
-
-  return priv->has_palette;
-}
-
-/**
- * gtk_color_selection_set_has_palette:
- * @colorsel: a #GtkColorSelection
- * @has_palette: %TRUE if palette is to be visible, %FALSE otherwise
- *
- * Shows and hides the palette based upon the value of @has_palette.
- */
-void
-gtk_color_selection_set_has_palette (GtkColorSelection *colorsel,
-                                     gboolean           has_palette)
-{
-  GtkColorSelectionPrivate *priv;
-  g_return_if_fail (GTK_IS_COLOR_SELECTION (colorsel));
-
-  priv = colorsel->private_data;
-  has_palette = has_palette != FALSE;
-
-  if (priv->has_palette != has_palette)
-    {
-      priv->has_palette = has_palette;
-      if (has_palette)
-        gtk_widget_show (priv->palette_frame);
-      else
-        gtk_widget_hide (priv->palette_frame);
-
-      update_tooltips (colorsel);
-
-      g_object_notify (G_OBJECT (colorsel), "has-palette");
-    }
-}
-
-/**
- * gtk_color_selection_set_current_color:
- * @colorsel: a #GtkColorSelection
- * @color: a #GdkColor to set the current color with
- *
- * Sets the current color to be @color.
- *
- * The first time this is called, it will also set
- * the original color to be @color too.
- *
- * Deprecated: 3.4: Use gtk_color_selection_set_current_rgba() instead.
- */
-void
-gtk_color_selection_set_current_color (GtkColorSelection *colorsel,
-                                       const GdkColor    *color)
-{
-  GtkColorSelectionPrivate *priv;
-  gint i;
-
-  g_return_if_fail (GTK_IS_COLOR_SELECTION (colorsel));
-  g_return_if_fail (color != NULL);
-
-  priv = colorsel->private_data;
-  priv->changing = TRUE;
-  priv->color[COLORSEL_RED] = SCALE (color->red);
-  priv->color[COLORSEL_GREEN] = SCALE (color->green);
-  priv->color[COLORSEL_BLUE] = SCALE (color->blue);
-  gtk_rgb_to_hsv (priv->color[COLORSEL_RED],
-                  priv->color[COLORSEL_GREEN],
-                  priv->color[COLORSEL_BLUE],
-                  &priv->color[COLORSEL_HUE],
-                  &priv->color[COLORSEL_SATURATION],
-                  &priv->color[COLORSEL_VALUE]);
-  if (priv->default_set == FALSE)
-    {
-      for (i = 0; i < COLORSEL_NUM_CHANNELS; i++)
-        priv->old_color[i] = priv->color[i];
-    }
-  priv->default_set = TRUE;
-  update_color (colorsel);
-}
-
-/**
- * gtk_color_selection_set_current_alpha:
- * @colorsel: a #GtkColorSelection
- * @alpha: an integer between 0 and 65535
- *
- * Sets the current opacity to be @alpha.
- *
- * The first time this is called, it will also set
- * the original opacity to be @alpha too.
- */
-void
-gtk_color_selection_set_current_alpha (GtkColorSelection *colorsel,
-                                       guint16            alpha)
-{
-  GtkColorSelectionPrivate *priv;
-  gint i;
-
-  g_return_if_fail (GTK_IS_COLOR_SELECTION (colorsel));
-
-  priv = colorsel->private_data;
-  priv->changing = TRUE;
-  priv->color[COLORSEL_OPACITY] = SCALE (alpha);
-  if (priv->default_alpha_set == FALSE)
-    {
-      for (i = 0; i < COLORSEL_NUM_CHANNELS; i++)
-        priv->old_color[i] = priv->color[i];
-    }
-  priv->default_alpha_set = TRUE;
-  update_color (colorsel);
-}
-
-/**
- * gtk_color_selection_get_current_color:
- * @colorsel: a #GtkColorSelection
- * @color: (out): a #GdkColor to fill in with the current color
- *
- * Sets @color to be the current color in the GtkColorSelection widget.
- *
- * Deprecated: 3.4: Use gtk_color_selection_get_current_rgba() instead.
- */
-void
-gtk_color_selection_get_current_color (GtkColorSelection *colorsel,
-                                       GdkColor          *color)
-{
-  GtkColorSelectionPrivate *priv;
-
-  g_return_if_fail (GTK_IS_COLOR_SELECTION (colorsel));
-  g_return_if_fail (color != NULL);
-
-  priv = colorsel->private_data;
-  color->red = UNSCALE (priv->color[COLORSEL_RED]);
-  color->green = UNSCALE (priv->color[COLORSEL_GREEN]);
-  color->blue = UNSCALE (priv->color[COLORSEL_BLUE]);
-}
-
-/**
- * gtk_color_selection_get_current_alpha:
- * @colorsel: a #GtkColorSelection
- *
- * Returns the current alpha value.
- *
- * Return value: an integer between 0 and 65535
- */
-guint16
-gtk_color_selection_get_current_alpha (GtkColorSelection *colorsel)
-{
-  GtkColorSelectionPrivate *priv;
-
-  g_return_val_if_fail (GTK_IS_COLOR_SELECTION (colorsel), 0);
-
-  priv = colorsel->private_data;
-  return priv->has_opacity ? UNSCALE (priv->color[COLORSEL_OPACITY]) : 65535;
-}
-
-/**
- * gtk_color_selection_set_previous_color:
- * @colorsel: a #GtkColorSelection
- * @color: a #GdkColor to set the previous color with
- *
- * Sets the 'previous' color to be @color.
- *
- * This function should be called with some hesitations,
- * as it might seem confusing to have that color change.
- * Calling gtk_color_selection_set_current_color() will also
- * set this color the first time it is called.
- *
- * Deprecated: 3.4: Use gtk_color_selection_set_previous_rgba() instead.
- */
-void
-gtk_color_selection_set_previous_color (GtkColorSelection *colorsel,
-                                        const GdkColor    *color)
-{
-  GtkColorSelectionPrivate *priv;
-
-  g_return_if_fail (GTK_IS_COLOR_SELECTION (colorsel));
-  g_return_if_fail (color != NULL);
-
-  priv = colorsel->private_data;
-  priv->changing = TRUE;
-  priv->old_color[COLORSEL_RED] = SCALE (color->red);
-  priv->old_color[COLORSEL_GREEN] = SCALE (color->green);
-  priv->old_color[COLORSEL_BLUE] = SCALE (color->blue);
-  gtk_rgb_to_hsv (priv->old_color[COLORSEL_RED],
-                  priv->old_color[COLORSEL_GREEN],
-                  priv->old_color[COLORSEL_BLUE],
-                  &priv->old_color[COLORSEL_HUE],
-                  &priv->old_color[COLORSEL_SATURATION],
-                  &priv->old_color[COLORSEL_VALUE]);
-  color_sample_update_samples (colorsel);
-  priv->default_set = TRUE;
-  priv->changing = FALSE;
-}
-
-/**
- * gtk_color_selection_set_previous_alpha:
- * @colorsel: a #GtkColorSelection
- * @alpha: an integer between 0 and 65535
- *
- * Sets the 'previous' alpha to be @alpha.
- *
- * This function should be called with some hesitations,
- * as it might seem confusing to have that alpha change.
- */
-void
-gtk_color_selection_set_previous_alpha (GtkColorSelection *colorsel,
-                                        guint16            alpha)
-{
-  GtkColorSelectionPrivate *priv;
-
-  g_return_if_fail (GTK_IS_COLOR_SELECTION (colorsel));
-
-  priv = colorsel->private_data;
-  priv->changing = TRUE;
-  priv->old_color[COLORSEL_OPACITY] = SCALE (alpha);
-  color_sample_update_samples (colorsel);
-  priv->default_alpha_set = TRUE;
-  priv->changing = FALSE;
-}
-
-
-/**
- * gtk_color_selection_get_previous_color:
- * @colorsel: a #GtkColorSelection
- * @color: (out): a #GdkColor to fill in with the original color value
- *
- * Fills @color in with the original color value.
- *
- * Deprecated: 3.4: Use gtk_color_selection_get_previous_rgba() instead.
- */
-void
-gtk_color_selection_get_previous_color (GtkColorSelection *colorsel,
-                                        GdkColor           *color)
-{
-  GtkColorSelectionPrivate *priv;
-
-  g_return_if_fail (GTK_IS_COLOR_SELECTION (colorsel));
-  g_return_if_fail (color != NULL);
-
-  priv = colorsel->private_data;
-  color->red = UNSCALE (priv->old_color[COLORSEL_RED]);
-  color->green = UNSCALE (priv->old_color[COLORSEL_GREEN]);
-  color->blue = UNSCALE (priv->old_color[COLORSEL_BLUE]);
-}
-
-/**
- * gtk_color_selection_get_previous_alpha:
- * @colorsel: a #GtkColorSelection
- *
- * Returns the previous alpha value.
- *
- * Return value: an integer between 0 and 65535
- */
-guint16
-gtk_color_selection_get_previous_alpha (GtkColorSelection *colorsel)
-{
-  GtkColorSelectionPrivate *priv;
-
-  g_return_val_if_fail (GTK_IS_COLOR_SELECTION (colorsel), 0);
-
-  priv = colorsel->private_data;
-  return priv->has_opacity ? UNSCALE (priv->old_color[COLORSEL_OPACITY]) : 65535;
-}
-
-/**
- * gtk_color_selection_set_current_rgba:
- * @colorsel: a #GtkColorSelection
- * @rgba: A #GdkRGBA to set the current color with
- *
- * Sets the current color to be @rgba.
- *
- * The first time this is called, it will also set
- * the original color to be @rgba too.
- *
- * Since: 3.0
- */
-void
-gtk_color_selection_set_current_rgba (GtkColorSelection *colorsel,
-                                      const GdkRGBA     *rgba)
-{
-  GtkColorSelectionPrivate *priv;
-  gint i;
-
-  g_return_if_fail (GTK_IS_COLOR_SELECTION (colorsel));
-  g_return_if_fail (rgba != NULL);
-
-  priv = colorsel->private_data;
-  priv->changing = TRUE;
-
-  priv->color[COLORSEL_RED] = CLAMP (rgba->red, 0, 1);
-  priv->color[COLORSEL_GREEN] = CLAMP (rgba->green, 0, 1);
-  priv->color[COLORSEL_BLUE] = CLAMP (rgba->blue, 0, 1);
-  priv->color[COLORSEL_OPACITY] = CLAMP (rgba->alpha, 0, 1);
-
-  gtk_rgb_to_hsv (priv->color[COLORSEL_RED],
-                  priv->color[COLORSEL_GREEN],
-                  priv->color[COLORSEL_BLUE],
-                  &priv->color[COLORSEL_HUE],
-                  &priv->color[COLORSEL_SATURATION],
-                  &priv->color[COLORSEL_VALUE]);
-
-  if (priv->default_set == FALSE)
-    {
-      for (i = 0; i < COLORSEL_NUM_CHANNELS; i++)
-        priv->old_color[i] = priv->color[i];
-    }
-
-  priv->default_set = TRUE;
-  update_color (colorsel);
-}
-
-/**
- * gtk_color_selection_get_current_rgba:
- * @colorsel: a #GtkColorSelection
- * @rgba: (out): a #GdkRGBA to fill in with the current color
- *
- * Sets @rgba to be the current color in the GtkColorSelection widget.
- *
- * Since: 3.0
- */
-void
-gtk_color_selection_get_current_rgba (GtkColorSelection *colorsel,
-                                      GdkRGBA           *rgba)
-{
-  GtkColorSelectionPrivate *priv;
-
-  g_return_if_fail (GTK_IS_COLOR_SELECTION (colorsel));
-  g_return_if_fail (rgba != NULL);
-
-  priv = colorsel->private_data;
-  rgba->red = priv->color[COLORSEL_RED];
-  rgba->green = priv->color[COLORSEL_GREEN];
-  rgba->blue = priv->color[COLORSEL_BLUE];
-  rgba->alpha = (priv->has_opacity) ? priv->color[COLORSEL_OPACITY] : 1;
-}
-
-/**
- * gtk_color_selection_set_previous_rgba:
- * @colorsel: a #GtkColorSelection
- * @rgba: a #GdkRGBA to set the previous color with
- *
- * Sets the 'previous' color to be @rgba.
- *
- * This function should be called with some hesitations,
- * as it might seem confusing to have that color change.
- * Calling gtk_color_selection_set_current_rgba() will also
- * set this color the first time it is called.
- *
- * Since: 3.0
- */
-void
-gtk_color_selection_set_previous_rgba (GtkColorSelection *colorsel,
-                                       const GdkRGBA     *rgba)
-{
-  GtkColorSelectionPrivate *priv;
-
-  g_return_if_fail (GTK_IS_COLOR_SELECTION (colorsel));
-  g_return_if_fail (rgba != NULL);
-
-  priv = colorsel->private_data;
-  priv->changing = TRUE;
-
-  priv->old_color[COLORSEL_RED] = CLAMP (rgba->red, 0, 1);
-  priv->old_color[COLORSEL_GREEN] = CLAMP (rgba->green, 0, 1);
-  priv->old_color[COLORSEL_BLUE] = CLAMP (rgba->blue, 0, 1);
-  priv->old_color[COLORSEL_OPACITY] = CLAMP (rgba->alpha, 0, 1);
-
-  gtk_rgb_to_hsv (priv->old_color[COLORSEL_RED],
-                  priv->old_color[COLORSEL_GREEN],
-                  priv->old_color[COLORSEL_BLUE],
-                  &priv->old_color[COLORSEL_HUE],
-                  &priv->old_color[COLORSEL_SATURATION],
-                  &priv->old_color[COLORSEL_VALUE]);
-
-  color_sample_update_samples (colorsel);
-  priv->default_set = TRUE;
-  priv->changing = FALSE;
-}
-
-/**
- * gtk_color_selection_get_previous_rgba:
- * @colorsel: a #GtkColorSelection
- * @rgba: (out): a #GdkRGBA to fill in with the original color value
- *
- * Fills @rgba in with the original color value.
- *
- * Since: 3.0
- */
-void
-gtk_color_selection_get_previous_rgba (GtkColorSelection *colorsel,
-                                       GdkRGBA           *rgba)
-{
-  GtkColorSelectionPrivate *priv;
-
-  g_return_if_fail (GTK_IS_COLOR_SELECTION (colorsel));
-  g_return_if_fail (rgba != NULL);
-
-  priv = colorsel->private_data;
-  rgba->red = priv->old_color[COLORSEL_RED];
-  rgba->green = priv->old_color[COLORSEL_GREEN];
-  rgba->blue = priv->old_color[COLORSEL_BLUE];
-  rgba->alpha = (priv->has_opacity) ? priv->old_color[COLORSEL_OPACITY] : 1;
-}
-
-/**
- * gtk_color_selection_set_palette_color:
- * @colorsel: a #GtkColorSelection
- * @index: the color index of the palette
- * @color: A #GdkColor to set the palette with
- *
- * Sets the palette located at @index to have @color as its color.
- */
-static void
-gtk_color_selection_set_palette_color (GtkColorSelection *colorsel,
-                                       gint               index,
-                                       GdkColor          *color)
-{
-  GtkColorSelectionPrivate *priv;
-  gint x, y;
-  gdouble col[3];
-
-  g_return_if_fail (GTK_IS_COLOR_SELECTION (colorsel));
-  g_return_if_fail (index >= 0  && index < GTK_CUSTOM_PALETTE_WIDTH*GTK_CUSTOM_PALETTE_HEIGHT);
-
-  x = index % GTK_CUSTOM_PALETTE_WIDTH;
-  y = index / GTK_CUSTOM_PALETTE_WIDTH;
-
-  priv = colorsel->private_data;
-  col[0] = SCALE (color->red);
-  col[1] = SCALE (color->green);
-  col[2] = SCALE (color->blue);
-
-  palette_set_color (priv->custom_palette[x][y], colorsel, col);
-}
-
-/**
- * gtk_color_selection_is_adjusting:
- * @colorsel: a #GtkColorSelection
- *
- * Gets the current state of the @colorsel.
- *
- * Return value: %TRUE if the user is currently dragging
- *     a color around, and %FALSE if the selection has stopped
- */
-gboolean
-gtk_color_selection_is_adjusting (GtkColorSelection *colorsel)
-{
-  GtkColorSelectionPrivate *priv;
-
-  g_return_val_if_fail (GTK_IS_COLOR_SELECTION (colorsel), FALSE);
-
-  priv = colorsel->private_data;
-
-  return (gtk_hsv_is_adjusting (GTK_HSV (priv->triangle_colorsel)));
-}
-
-
-/**
- * gtk_color_selection_palette_from_string:
- * @str: a string encoding a color palette
- * @colors: (out) (array length=n_colors): return location for
- *     allocated array of #GdkColor
- * @n_colors: return location for length of array
- *
- * Parses a color palette string; the string is a colon-separated
- * list of color names readable by gdk_color_parse().
- *
- * Return value: %TRUE if a palette was successfully parsed
- */
-gboolean
-gtk_color_selection_palette_from_string (const gchar  *str,
-                                         GdkColor    **colors,
-                                         gint         *n_colors)
-{
-  GdkColor *retval;
-  gint count;
-  gchar *p;
-  gchar *start;
-  gchar *copy;
-
-  count = 0;
-  retval = NULL;
-  copy = g_strdup (str);
-
-  start = copy;
-  p = copy;
-  while (TRUE)
-    {
-      if (*p == ':' || *p == '\0')
-        {
-          gboolean done = TRUE;
-
-          if (start == p)
-            {
-              goto failed; /* empty entry */
-            }
-
-          if (*p)
-            {
-              *p = '\0';
-              done = FALSE;
-            }
-
-          retval = g_renew (GdkColor, retval, count + 1);
-          if (!gdk_color_parse (start, retval + count))
-            {
-              goto failed;
-            }
-
-          ++count;
-
-          if (done)
-            break;
-          else
-            start = p + 1;
-        }
-
-      ++p;
-    }
-
-  g_free (copy);
-
-  if (colors)
-    *colors = retval;
-  else
-    g_free (retval);
-
-  if (n_colors)
-    *n_colors = count;
-
-  return TRUE;
-
- failed:
-  g_free (copy);
-  g_free (retval);
-
-  if (colors)
-    *colors = NULL;
-  if (n_colors)
-    *n_colors = 0;
-
-  return FALSE;
-}
-
-/**
- * gtk_color_selection_palette_to_string:
- * @colors: (array length=n_colors): an array of colors
- * @n_colors: length of the array
- *
- * Encodes a palette as a string, useful for persistent storage.
- *
- * Return value: allocated string encoding the palette
- */
-gchar*
-gtk_color_selection_palette_to_string (const GdkColor *colors,
-                                       gint            n_colors)
-{
-  gint i;
-  gchar **strs = NULL;
-  gchar *retval;
-
-  if (n_colors == 0)
-    return g_strdup ("");
-
-  strs = g_new0 (gchar*, n_colors + 1);
-
-  i = 0;
-  while (i < n_colors)
-    {
-      gchar *ptr;
-
-      strs[i] =
-        g_strdup_printf ("#%2X%2X%2X",
-                         colors[i].red / 256,
-                         colors[i].green / 256,
-                         colors[i].blue / 256);
-
-      for (ptr = strs[i]; *ptr; ptr++)
-        if (*ptr == ' ')
-          *ptr = '0';
-
-      ++i;
-    }
-
-  retval = g_strjoinv (":", strs);
-
-  g_strfreev (strs);
-
-  return retval;
-}
-
-/**
- * gtk_color_selection_set_change_palette_with_screen_hook: (skip)
- * @func: a function to call when the custom palette needs saving
- *
- * Installs a global function to be called whenever the user
- * tries to modify the palette in a color selection.
- *
- * This function should save the new palette contents, and update
- * the #GtkSettings::gtk-color-palette GtkSettings property so all
- * GtkColorSelection widgets will be modified.
- *
- * Return value: the previous change palette hook (that was replaced)
- *
- * Since: 2.2
- */
-GtkColorSelectionChangePaletteWithScreenFunc
-gtk_color_selection_set_change_palette_with_screen_hook (GtkColorSelectionChangePaletteWithScreenFunc func)
-{
-  GtkColorSelectionChangePaletteWithScreenFunc old;
-
-  old = change_palette_hook;
-
-  change_palette_hook = func;
-
-  return old;
-}
-
-static void
-make_control_relations (AtkObject *atk_obj,
-                        GtkWidget *widget)
-{
-  AtkObject *obj;
-
-  obj = gtk_widget_get_accessible (widget);
-  atk_object_add_relationship (atk_obj, ATK_RELATION_CONTROLLED_BY, obj);
-  atk_object_add_relationship (obj, ATK_RELATION_CONTROLLER_FOR, atk_obj);
-}
-
-static void
-make_all_relations (AtkObject                *atk_obj,
-                    GtkColorSelectionPrivate *priv)
-{
-  make_control_relations (atk_obj, priv->hue_spinbutton);
-  make_control_relations (atk_obj, priv->sat_spinbutton);
-  make_control_relations (atk_obj, priv->val_spinbutton);
-  make_control_relations (atk_obj, priv->red_spinbutton);
-  make_control_relations (atk_obj, priv->green_spinbutton);
-  make_control_relations (atk_obj, priv->blue_spinbutton);
-}
diff --git a/gtk/gtkcolorsel.h b/gtk/gtkcolorsel.h
deleted file mode 100644 (file)
index d8b7877..0000000
+++ /dev/null
@@ -1,143 +0,0 @@
-/* GTK - The GIMP Toolkit
- * Copyright (C) 2000 Red Hat, Inc.
- * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
- */
-
-/*
- * Modified by the GTK+ Team and others 1997-2000.  See the AUTHORS
- * file for a list of people on the GTK+ Team.  See the ChangeLog
- * files for a list of changes.  These files are distributed with
- * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
- */
-
-#if !defined (__GTK_H_INSIDE__) && !defined (GTK_COMPILATION)
-#error "Only <gtk/gtk.h> can be included directly."
-#endif
-
-#ifndef __GTK_COLOR_SELECTION_H__
-#define __GTK_COLOR_SELECTION_H__
-
-#include <gtk/gtkdialog.h>
-#include <gtk/gtkbox.h>
-
-G_BEGIN_DECLS
-
-#define GTK_TYPE_COLOR_SELECTION                       (gtk_color_selection_get_type ())
-#define GTK_COLOR_SELECTION(obj)                       (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_COLOR_SELECTION, GtkColorSelection))
-#define GTK_COLOR_SELECTION_CLASS(klass)               (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_COLOR_SELECTION, GtkColorSelectionClass))
-#define GTK_IS_COLOR_SELECTION(obj)                    (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_COLOR_SELECTION))
-#define GTK_IS_COLOR_SELECTION_CLASS(klass)            (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_COLOR_SELECTION))
-#define GTK_COLOR_SELECTION_GET_CLASS(obj)              (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_COLOR_SELECTION, GtkColorSelectionClass))
-
-
-typedef struct _GtkColorSelection       GtkColorSelection;
-typedef struct _GtkColorSelectionPrivate  GtkColorSelectionPrivate;
-typedef struct _GtkColorSelectionClass  GtkColorSelectionClass;
-
-typedef void (* GtkColorSelectionChangePaletteFunc) (const GdkColor    *colors,
-                                                     gint               n_colors);
-
-/**
- * GtkColorSelectionChangePaletteWithScreenFunc:
- * @screen:
- * @colors:
- * @n_colors:
- *
- * Since: 2.2
- */
-typedef void (* GtkColorSelectionChangePaletteWithScreenFunc) (GdkScreen         *screen,
-                                                              const GdkColor    *colors,
-                                                              gint               n_colors);
-
-struct _GtkColorSelection
-{
-  GtkBox parent_instance;
-
-  /* < private_data > */
-  GtkColorSelectionPrivate *private_data;
-};
-
-struct _GtkColorSelectionClass
-{
-  GtkBoxClass parent_class;
-
-  void (*color_changed)        (GtkColorSelection *color_selection);
-
-  /* Padding for future expansion */
-  void (*_gtk_reserved1) (void);
-  void (*_gtk_reserved2) (void);
-  void (*_gtk_reserved3) (void);
-  void (*_gtk_reserved4) (void);
-};
-
-
-/* ColorSelection */
-
-GType      gtk_color_selection_get_type                (void) G_GNUC_CONST;
-GtkWidget *gtk_color_selection_new                     (void);
-gboolean   gtk_color_selection_get_has_opacity_control (GtkColorSelection *colorsel);
-void       gtk_color_selection_set_has_opacity_control (GtkColorSelection *colorsel,
-                                                       gboolean           has_opacity);
-gboolean   gtk_color_selection_get_has_palette         (GtkColorSelection *colorsel);
-void       gtk_color_selection_set_has_palette         (GtkColorSelection *colorsel,
-                                                       gboolean           has_palette);
-
-
-void     gtk_color_selection_set_current_alpha   (GtkColorSelection *colorsel,
-                                                 guint16            alpha);
-guint16  gtk_color_selection_get_current_alpha   (GtkColorSelection *colorsel);
-void     gtk_color_selection_set_previous_alpha  (GtkColorSelection *colorsel,
-                                                 guint16            alpha);
-guint16  gtk_color_selection_get_previous_alpha  (GtkColorSelection *colorsel);
-
-void     gtk_color_selection_set_current_rgba    (GtkColorSelection *colorsel,
-                                                  const GdkRGBA     *rgba);
-void     gtk_color_selection_get_current_rgba    (GtkColorSelection *colorsel,
-                                                  GdkRGBA           *rgba);
-void     gtk_color_selection_set_previous_rgba   (GtkColorSelection *colorsel,
-                                                  const GdkRGBA     *rgba);
-void     gtk_color_selection_get_previous_rgba   (GtkColorSelection *colorsel,
-                                                  GdkRGBA           *rgba);
-
-gboolean gtk_color_selection_is_adjusting        (GtkColorSelection *colorsel);
-
-gboolean gtk_color_selection_palette_from_string (const gchar       *str,
-                                                  GdkColor         **colors,
-                                                  gint              *n_colors);
-gchar*   gtk_color_selection_palette_to_string   (const GdkColor    *colors,
-                                                  gint               n_colors);
-
-GtkColorSelectionChangePaletteWithScreenFunc gtk_color_selection_set_change_palette_with_screen_hook (GtkColorSelectionChangePaletteWithScreenFunc func);
-
-GDK_DEPRECATED_FOR(gtk_color_selection_set_current_rgba)
-void     gtk_color_selection_set_current_color   (GtkColorSelection *colorsel,
-                                                  const GdkColor    *color);
-GDK_DEPRECATED_FOR(gtk_color_selection_get_current_rgba)
-void     gtk_color_selection_get_current_color   (GtkColorSelection *colorsel,
-                                                  GdkColor          *color);
-GDK_DEPRECATED_FOR(gtk_color_selection_set_previous_rgba)
-void     gtk_color_selection_set_previous_color  (GtkColorSelection *colorsel,
-                                                  const GdkColor    *color);
-GDK_DEPRECATED_FOR(gtk_color_selection_get_previous_rgba)
-void     gtk_color_selection_get_previous_color  (GtkColorSelection *colorsel,
-                                                  GdkColor          *color);
-
-
-G_END_DECLS
-
-#endif /* __GTK_COLOR_SELECTION_H__ */
diff --git a/gtk/gtkcolorseldialog.c b/gtk/gtkcolorseldialog.c
deleted file mode 100644 (file)
index a8a77e7..0000000
+++ /dev/null
@@ -1,286 +0,0 @@
-/* GTK - The GIMP Toolkit
- * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
- */
-
-/*
- * Modified by the GTK+ Team and others 1997-2000.  See the AUTHORS
- * file for a list of people on the GTK+ Team.  See the ChangeLog
- * files for a list of changes.  These files are distributed with
- * GTK+ at ftp://ftp.gtk.org/pub/gtk/. 
- */
-#include "config.h"
-#include <string.h>
-#include <glib.h>
-#include "gtkcolorseldialog.h"
-#include "gtkframe.h"
-#include "gtkbutton.h"
-#include "gtkstock.h"
-#include "gtkintl.h"
-#include "gtkbuildable.h"
-
-
-/**
- * SECTION:gtkcolorseldlg
- * @Short_description: A standard dialog box for selecting a color
- * @Title: GtkColorSelectionDialog
- *
- * The #GtkColorSelectionDialog provides a standard dialog which
- * allows the user to select a color much like the #GtkFileSelection
- * provides a standard dialog for file selection.
- *
- * Use gtk_color_selection_dialog_get_color_selection() to get the
- * #GtkColorSelection widget contained within the dialog. Use this widget
- * and its gtk_color_selection_get_current_color()
- * function to gain access to the selected color.  Connect a handler
- * for this widget's #GtkColorSelection::color-changed signal to be notified
- * when the color changes.
- *
- * <refsect2 id="GtkColorSelectionDialog-BUILDER-UI">
- * <title>GtkColorSelectionDialog as GtkBuildable</title>
- * The GtkColorSelectionDialog implementation of the GtkBuildable interface
- * exposes the embedded #GtkColorSelection as internal child with the
- * name "color_selection". It also exposes the buttons with the names
- * "ok_button", "cancel_button" and "help_button".
- * </refsect2>
- */
-
-
-struct _GtkColorSelectionDialogPrivate
-{
-  GtkWidget *colorsel;
-  GtkWidget *ok_button;
-  GtkWidget *cancel_button;
-  GtkWidget *help_button;
-};
-
-enum {
-  PROP_0,
-  PROP_COLOR_SELECTION,
-  PROP_OK_BUTTON,
-  PROP_CANCEL_BUTTON,
-  PROP_HELP_BUTTON
-};
-
-
-/***************************/
-/* GtkColorSelectionDialog */
-/***************************/
-
-static void gtk_color_selection_dialog_buildable_interface_init     (GtkBuildableIface *iface);
-static GObject * gtk_color_selection_dialog_buildable_get_internal_child (GtkBuildable *buildable,
-                                                                         GtkBuilder   *builder,
-                                                                         const gchar  *childname);
-
-G_DEFINE_TYPE_WITH_CODE (GtkColorSelectionDialog, gtk_color_selection_dialog,
-           GTK_TYPE_DIALOG,
-           G_IMPLEMENT_INTERFACE (GTK_TYPE_BUILDABLE,
-                      gtk_color_selection_dialog_buildable_interface_init))
-
-static GtkBuildableIface *parent_buildable_iface;
-
-static void
-gtk_color_selection_dialog_get_property (GObject         *object,
-                                        guint            prop_id,
-                                        GValue          *value,
-                                        GParamSpec      *pspec)
-{
-  GtkColorSelectionDialog *colorsel = GTK_COLOR_SELECTION_DIALOG (object);
-  GtkColorSelectionDialogPrivate *priv = colorsel->priv;
-
-  switch (prop_id)
-    {
-    case PROP_COLOR_SELECTION:
-      g_value_set_object (value, priv->colorsel);
-      break;
-    case PROP_OK_BUTTON:
-      g_value_set_object (value, priv->ok_button);
-      break;
-    case PROP_CANCEL_BUTTON:
-      g_value_set_object (value, priv->cancel_button);
-      break;
-    case PROP_HELP_BUTTON:
-      g_value_set_object (value, priv->help_button);
-      break;
-    default:
-      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
-      break;
-    }
-}
-
-static void
-gtk_color_selection_dialog_class_init (GtkColorSelectionDialogClass *klass)
-{
-  GObjectClass   *gobject_class = G_OBJECT_CLASS (klass);
-  GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
-
-  gobject_class->get_property = gtk_color_selection_dialog_get_property;
-
-  g_object_class_install_property (gobject_class,
-                                  PROP_COLOR_SELECTION,
-                                  g_param_spec_object ("color-selection",
-                                                    P_("Color Selection"),
-                                                    P_("The color selection embedded in the dialog."),
-                                                    GTK_TYPE_WIDGET,
-                                                    G_PARAM_READABLE));
-  g_object_class_install_property (gobject_class,
-                                  PROP_OK_BUTTON,
-                                  g_param_spec_object ("ok-button",
-                                                    P_("OK Button"),
-                                                    P_("The OK button of the dialog."),
-                                                    GTK_TYPE_WIDGET,
-                                                    G_PARAM_READABLE));
-  g_object_class_install_property (gobject_class,
-                                  PROP_CANCEL_BUTTON,
-                                  g_param_spec_object ("cancel-button",
-                                                    P_("Cancel Button"),
-                                                    P_("The cancel button of the dialog."),
-                                                    GTK_TYPE_WIDGET,
-                                                    G_PARAM_READABLE));
-  g_object_class_install_property (gobject_class,
-                                  PROP_HELP_BUTTON,
-                                  g_param_spec_object ("help-button",
-                                                    P_("Help Button"),
-                                                    P_("The help button of the dialog."),
-                                                    GTK_TYPE_WIDGET,
-                                                    G_PARAM_READABLE));
-
-  gtk_widget_class_set_accessible_role (widget_class, ATK_ROLE_COLOR_CHOOSER);
-
-  g_type_class_add_private (klass, sizeof (GtkColorSelectionDialogPrivate));
-}
-
-static void
-gtk_color_selection_dialog_init (GtkColorSelectionDialog *colorseldiag)
-{
-  GtkColorSelectionDialogPrivate *priv;
-  GtkDialog *dialog = GTK_DIALOG (colorseldiag);
-  GtkWidget *action_area, *content_area;
-
-  colorseldiag->priv = G_TYPE_INSTANCE_GET_PRIVATE (colorseldiag,
-                                                    GTK_TYPE_COLOR_SELECTION_DIALOG,
-                                                    GtkColorSelectionDialogPrivate);
-  priv = colorseldiag->priv;
-
-  content_area = gtk_dialog_get_content_area (dialog);
-  action_area = gtk_dialog_get_action_area (dialog);
-
-  gtk_container_set_border_width (GTK_CONTAINER (dialog), 5);
-  gtk_box_set_spacing (GTK_BOX (content_area), 2); /* 2 * 5 + 2 = 12 */
-  gtk_container_set_border_width (GTK_CONTAINER (action_area), 5);
-  gtk_box_set_spacing (GTK_BOX (action_area), 6);
-
-  priv->colorsel = gtk_color_selection_new ();
-  gtk_container_set_border_width (GTK_CONTAINER (priv->colorsel), 5);
-  gtk_color_selection_set_has_palette (GTK_COLOR_SELECTION (priv->colorsel), FALSE);
-  gtk_color_selection_set_has_opacity_control (GTK_COLOR_SELECTION (priv->colorsel), FALSE);
-  gtk_container_add (GTK_CONTAINER (content_area), priv->colorsel);
-  gtk_widget_show (priv->colorsel);
-
-  priv->cancel_button = gtk_dialog_add_button (dialog,
-                                               GTK_STOCK_CANCEL,
-                                               GTK_RESPONSE_CANCEL);
-
-  priv->ok_button = gtk_dialog_add_button (dialog,
-                                           _("_Select"),
-                                           GTK_RESPONSE_OK);
-
-  gtk_widget_grab_default (priv->ok_button);
-
-  priv->help_button = gtk_dialog_add_button (dialog,
-                                             GTK_STOCK_HELP,
-                                             GTK_RESPONSE_HELP);
-
-  gtk_widget_hide (priv->help_button);
-
-  gtk_dialog_set_alternative_button_order (dialog,
-                                          GTK_RESPONSE_OK,
-                                          GTK_RESPONSE_CANCEL,
-                                          GTK_RESPONSE_HELP,
-                                          -1);
-
-  gtk_window_set_title (GTK_WINDOW (colorseldiag),
-                        _("Color Selection"));
-}
-
-/**
- * gtk_color_selection_dialog_new:
- * @title: a string containing the title text for the dialog.
- *
- * Creates a new #GtkColorSelectionDialog.
- *
- * Returns: a #GtkColorSelectionDialog.
- */
-GtkWidget*
-gtk_color_selection_dialog_new (const gchar *title)
-{
-  GtkColorSelectionDialog *colorseldiag;
-  
-  colorseldiag = g_object_new (GTK_TYPE_COLOR_SELECTION_DIALOG, NULL);
-
-  if (title)
-    gtk_window_set_title (GTK_WINDOW (colorseldiag), title);
-
-  gtk_window_set_resizable (GTK_WINDOW (colorseldiag), FALSE);
-  
-  return GTK_WIDGET (colorseldiag);
-}
-
-/**
- * gtk_color_selection_dialog_get_color_selection:
- * @colorsel: a #GtkColorSelectionDialog
- *
- * Retrieves the #GtkColorSelection widget embedded in the dialog.
- *
- * Returns: (transfer none): the embedded #GtkColorSelection
- *
- * Since: 2.14
- **/
-GtkWidget*
-gtk_color_selection_dialog_get_color_selection (GtkColorSelectionDialog *colorsel)
-{
-  g_return_val_if_fail (GTK_IS_COLOR_SELECTION_DIALOG (colorsel), NULL);
-
-  return colorsel->priv->colorsel;
-}
-
-static void
-gtk_color_selection_dialog_buildable_interface_init (GtkBuildableIface *iface)
-{
-  parent_buildable_iface = g_type_interface_peek_parent (iface);
-  iface->get_internal_child = gtk_color_selection_dialog_buildable_get_internal_child;
-}
-
-static GObject *
-gtk_color_selection_dialog_buildable_get_internal_child (GtkBuildable *buildable,
-                                                        GtkBuilder   *builder,
-                                                        const gchar  *childname)
-{
-  GtkColorSelectionDialog *selection_dialog = GTK_COLOR_SELECTION_DIALOG (buildable);
-  GtkColorSelectionDialogPrivate *priv = selection_dialog->priv;
-
-  if (g_strcmp0 (childname, "ok_button") == 0)
-    return G_OBJECT (priv->ok_button);
-  else if (g_strcmp0 (childname, "cancel_button") == 0)
-    return G_OBJECT (priv->cancel_button);
-  else if (g_strcmp0 (childname, "help_button") == 0)
-    return G_OBJECT (priv->help_button);
-  else if (g_strcmp0 (childname, "color_selection") == 0)
-    return G_OBJECT (priv->colorsel);
-
-  return parent_buildable_iface->get_internal_child (buildable, builder, childname);
-}
diff --git a/gtk/gtkcolorseldialog.h b/gtk/gtkcolorseldialog.h
deleted file mode 100644 (file)
index aeaa507..0000000
+++ /dev/null
@@ -1,80 +0,0 @@
-/* GTK - The GIMP Toolkit
- * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
- */
-
-/*
- * Modified by the GTK+ Team and others 1997-2000.  See the AUTHORS
- * file for a list of people on the GTK+ Team.  See the ChangeLog
- * files for a list of changes.  These files are distributed with
- * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
- */
-
-#if !defined (__GTK_H_INSIDE__) && !defined (GTK_COMPILATION)
-#error "Only <gtk/gtk.h> can be included directly."
-#endif
-
-#ifndef __GTK_COLOR_SELECTION_DIALOG_H__
-#define __GTK_COLOR_SELECTION_DIALOG_H__
-
-#include <gtk/gtkdialog.h>
-#include <gtk/gtkcolorsel.h>
-
-G_BEGIN_DECLS
-
-#define GTK_TYPE_COLOR_SELECTION_DIALOG            (gtk_color_selection_dialog_get_type ())
-#define GTK_COLOR_SELECTION_DIALOG(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_COLOR_SELECTION_DIALOG, GtkColorSelectionDialog))
-#define GTK_COLOR_SELECTION_DIALOG_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_COLOR_SELECTION_DIALOG, GtkColorSelectionDialogClass))
-#define GTK_IS_COLOR_SELECTION_DIALOG(obj)         (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_COLOR_SELECTION_DIALOG))
-#define GTK_IS_COLOR_SELECTION_DIALOG_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_COLOR_SELECTION_DIALOG))
-#define GTK_COLOR_SELECTION_DIALOG_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_COLOR_SELECTION_DIALOG, GtkColorSelectionDialogClass))
-
-
-typedef struct _GtkColorSelectionDialog              GtkColorSelectionDialog;
-typedef struct _GtkColorSelectionDialogPrivate       GtkColorSelectionDialogPrivate;
-typedef struct _GtkColorSelectionDialogClass         GtkColorSelectionDialogClass;
-
-
-struct _GtkColorSelectionDialog
-{
-  GtkDialog parent_instance;
-
-  /*< private >*/
-  GtkColorSelectionDialogPrivate *priv;
-};
-
-struct _GtkColorSelectionDialogClass
-{
-  GtkDialogClass parent_class;
-
-  /* Padding for future expansion */
-  void (*_gtk_reserved1) (void);
-  void (*_gtk_reserved2) (void);
-  void (*_gtk_reserved3) (void);
-  void (*_gtk_reserved4) (void);
-};
-
-
-/* ColorSelectionDialog */
-GType      gtk_color_selection_dialog_get_type            (void) G_GNUC_CONST;
-GtkWidget* gtk_color_selection_dialog_new                 (const gchar *title);
-GtkWidget* gtk_color_selection_dialog_get_color_selection (GtkColorSelectionDialog *colorsel);
-
-
-G_END_DECLS
-
-#endif /* __GTK_COLOR_SELECTION_DIALOG_H__ */
diff --git a/gtk/gtkcolorutils.c b/gtk/gtkcolorutils.c
new file mode 100644 (file)
index 0000000..ef63712
--- /dev/null
@@ -0,0 +1,260 @@
+/* Color utilities
+ *
+ * Copyright (C) 1999 The Free Software Foundation
+ *
+ * Authors: Simon Budig <Simon.Budig@unix-ag.org> (original code)
+ *          Federico Mena-Quintero <federico@gimp.org> (cleanup for GTK+)
+ *          Jonathan Blandford <jrb@redhat.com> (cleanup for GTK+)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+/*
+ * Modified by the GTK+ Team and others 1997-2000.  See the AUTHORS
+ * file for a list of people on the GTK+ Team.  See the ChangeLog
+ * files for a list of changes.  These files are distributed with
+ * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
+ */
+
+#include "config.h"
+
+#include <math.h>
+#include <string.h>
+
+#include "gtkcolorutils.h"
+
+
+#define INTENSITY(r, g, b) ((r) * 0.30 + (g) * 0.59 + (b) * 0.11)
+
+/* Converts from HSV to RGB */
+static void
+hsv_to_rgb (gdouble *h,
+            gdouble *s,
+            gdouble *v)
+{
+  gdouble hue, saturation, value;
+  gdouble f, p, q, t;
+
+  if (*s == 0.0)
+    {
+      *h = *v;
+      *s = *v;
+      *v = *v; /* heh */
+    }
+  else
+    {
+      hue = *h * 6.0;
+      saturation = *s;
+      value = *v;
+
+      if (hue == 6.0)
+        hue = 0.0;
+
+      f = hue - (int) hue;
+      p = value * (1.0 - saturation);
+      q = value * (1.0 - saturation * f);
+      t = value * (1.0 - saturation * (1.0 - f));
+
+      switch ((int) hue)
+        {
+        case 0:
+          *h = value;
+          *s = t;
+          *v = p;
+          break;
+
+        case 1:
+          *h = q;
+          *s = value;
+          *v = p;
+          break;
+
+        case 2:
+          *h = p;
+          *s = value;
+          *v = t;
+          break;
+
+        case 3:
+          *h = p;
+          *s = q;
+          *v = value;
+          break;
+
+        case 4:
+          *h = t;
+          *s = p;
+          *v = value;
+          break;
+
+        case 5:
+          *h = value;
+          *s = p;
+          *v = q;
+          break;
+
+        default:
+          g_assert_not_reached ();
+        }
+    }
+}
+
+/* Converts from RGB to HSV */
+static void
+rgb_to_hsv (gdouble *r,
+            gdouble *g,
+            gdouble *b)
+{
+  gdouble red, green, blue;
+  gdouble h, s, v;
+  gdouble min, max;
+  gdouble delta;
+
+  red = *r;
+  green = *g;
+  blue = *b;
+
+  h = 0.0;
+
+  if (red > green)
+    {
+      if (red > blue)
+        max = red;
+      else
+        max = blue;
+
+      if (green < blue)
+        min = green;
+      else
+        min = blue;
+    }
+  else
+    {
+      if (green > blue)
+        max = green;
+      else
+        max = blue;
+
+      if (red < blue)
+        min = red;
+      else
+        min = blue;
+    }
+
+  v = max;
+
+  if (max != 0.0)
+    s = (max - min) / max;
+  else
+    s = 0.0;
+
+  if (s == 0.0)
+    h = 0.0;
+  else
+    {
+      delta = max - min;
+
+      if (red == max)
+        h = (green - blue) / delta;
+      else if (green == max)
+        h = 2 + (blue - red) / delta;
+      else if (blue == max)
+        h = 4 + (red - green) / delta;
+
+      h /= 6.0;
+
+      if (h < 0.0)
+        h += 1.0;
+      else if (h > 1.0)
+        h -= 1.0;
+    }
+
+  *r = h;
+  *g = s;
+  *b = v;
+}
+
+/**
+ * gtk_hsv_to_rgb:
+ * @h: Hue
+ * @s: Saturation
+ * @v: Value
+ * @r: (out): Return value for the red component
+ * @g: (out): Return value for the green component
+ * @b: (out): Return value for the blue component
+ *
+ * Converts a color from HSV space to RGB.
+ *
+ * Input values must be in the [0.0, 1.0] range;
+ * output values will be in the same range.
+ *
+ * Since: 2.14
+ */
+void
+gtk_hsv_to_rgb (gdouble  h, gdouble  s, gdouble  v,
+                gdouble *r, gdouble *g, gdouble *b)
+{
+  g_return_if_fail (h >= 0.0 && h <= 1.0);
+  g_return_if_fail (s >= 0.0 && s <= 1.0);
+  g_return_if_fail (v >= 0.0 && v <= 1.0);
+
+  hsv_to_rgb (&h, &s, &v);
+
+  if (r)
+    *r = h;
+
+  if (g)
+    *g = s;
+
+  if (b)
+    *b = v;
+}
+
+/**
+ * gtk_rgb_to_hsv:
+ * @r: Red
+ * @g: Green
+ * @b: Blue
+ * @h: (out): Return value for the hue component
+ * @s: (out): Return value for the saturation component
+ * @v: (out): Return value for the value component
+ *
+ * Converts a color from RGB space to HSV.
+ *
+ * Input values must be in the [0.0, 1.0] range;
+ * output values will be in the same range.
+ *
+ * Since: 2.14
+ */
+void
+gtk_rgb_to_hsv (gdouble  r, gdouble  g, gdouble  b,
+                gdouble *h, gdouble *s, gdouble *v)
+{
+  g_return_if_fail (r >= 0.0 && r <= 1.0);
+  g_return_if_fail (g >= 0.0 && g <= 1.0);
+  g_return_if_fail (b >= 0.0 && b <= 1.0);
+
+  rgb_to_hsv (&r, &g, &b);
+
+  if (h)
+    *h = r;
+
+  if (s)
+    *s = g;
+
+  if (v)
+    *v = b;
+}
diff --git a/gtk/gtkcolorutils.h b/gtk/gtkcolorutils.h
new file mode 100644 (file)
index 0000000..cef16b9
--- /dev/null
@@ -0,0 +1,48 @@
+/* Color utilties
+ *
+ * Copyright (C) 1999 The Free Software Foundation
+ *
+ * Authors: Simon Budig <Simon.Budig@unix-ag.org> (original code)
+ *          Federico Mena-Quintero <federico@gimp.org> (cleanup for GTK+)
+ *          Jonathan Blandford <jrb@redhat.com> (cleanup for GTK+)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+/*
+ * Modified by the GTK+ Team and others 1997-2000.  See the AUTHORS
+ * file for a list of people on the GTK+ Team.  See the ChangeLog
+ * files for a list of changes.  These files are distributed with
+ * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
+ */
+
+#if !defined (__GTK_H_INSIDE__) && !defined (GTK_COMPILATION)
+#error "Only <gtk/gtk.h> can be included directly."
+#endif
+
+#ifndef __GTK_COLOR_UTILS_H__
+#define __GTK_COLOR_UTILS_H__
+
+#include <glib.h>
+
+void gtk_hsv_to_rgb (gdouble  h, gdouble  s, gdouble  v,
+                     gdouble *r, gdouble *g, gdouble *b);
+void gtk_rgb_to_hsv (gdouble  r, gdouble  g, gdouble  b,
+                     gdouble *h, gdouble *s, gdouble *v);
+
+G_END_DECLS
+
+#endif /* __GTK_COLOR_UTILS_H__ */
diff --git a/gtk/gtkhsv.c b/gtk/gtkhsv.c
deleted file mode 100644 (file)
index e375667..0000000
+++ /dev/null
@@ -1,1610 +0,0 @@
-/* HSV color selector for GTK+
- *
- * Copyright (C) 1999 The Free Software Foundation
- *
- * Authors: Simon Budig <Simon.Budig@unix-ag.org> (original code)
- *          Federico Mena-Quintero <federico@gimp.org> (cleanup for GTK+)
- *          Jonathan Blandford <jrb@redhat.com> (cleanup for GTK+)
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
- */
-
-/*
- * Modified by the GTK+ Team and others 1997-2000.  See the AUTHORS
- * file for a list of people on the GTK+ Team.  See the ChangeLog
- * files for a list of changes.  These files are distributed with
- * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
- */
-
-#include "config.h"
-
-#include <math.h>
-#include <string.h>
-
-#include "gtkhsv.h"
-#include "gtkbindings.h"
-#include "gtkmarshalers.h"
-#include "gtktypebuiltins.h"
-#include "gtkintl.h"
-
-
-/**
- * SECTION:gtkhsv
- * @Short_description: A 'color wheel' widget
- * @Title: GtkHSV
- * @See_also: #GtkColorSelection, #GtkColorSelectionDialog
- *
- * #GtkHSV is the 'color wheel' part of a complete color selector widget.
- * It allows to select a color by determining its HSV components in an
- * intuitive way. Moving the selection around the outer ring changes the hue,
- * and moving the selection point inside the inner triangle changes value and
- * saturation.
- */
-
-
-/* Default width/height */
-#define DEFAULT_SIZE 100
-
-/* Default ring width */
-#define DEFAULT_RING_WIDTH 10
-
-
-/* Dragging modes */
-typedef enum {
-  DRAG_NONE,
-  DRAG_H,
-  DRAG_SV
-} DragMode;
-
-/* Private part of the GtkHSV structure */
-struct _GtkHSVPrivate
-{
-  /* Color value */
-  double h;
-  double s;
-  double v;
-  
-  /* Size and ring width */
-  int size;
-  int ring_width;
-  
-  /* Window for capturing events */
-  GdkWindow *window;
-  
-  /* Dragging mode */
-  DragMode mode;
-
-  guint focus_on_ring : 1;
-};
-
-
-/* Signal IDs */
-
-enum {
-  CHANGED,
-  MOVE,
-  LAST_SIGNAL
-};
-
-static void     gtk_hsv_destroy              (GtkWidget          *widget);
-static void     gtk_hsv_realize              (GtkWidget          *widget);
-static void     gtk_hsv_unrealize            (GtkWidget          *widget);
-static void     gtk_hsv_get_preferred_width  (GtkWidget          *widget,
-                                              gint               *minimum,
-                                              gint               *natural);
-static void     gtk_hsv_get_preferred_height (GtkWidget          *widget,
-                                              gint               *minimum,
-                                              gint               *natural);
-static void     gtk_hsv_size_allocate        (GtkWidget          *widget,
-                                              GtkAllocation      *allocation);
-static gboolean gtk_hsv_button_press         (GtkWidget          *widget,
-                                              GdkEventButton     *event);
-static gboolean gtk_hsv_button_release       (GtkWidget          *widget,
-                                              GdkEventButton     *event);
-static gboolean gtk_hsv_motion               (GtkWidget          *widget,
-                                              GdkEventMotion     *event);
-static gboolean gtk_hsv_draw                 (GtkWidget          *widget,
-                                              cairo_t            *cr);
-static gboolean gtk_hsv_grab_broken          (GtkWidget          *widget,
-                                              GdkEventGrabBroken *event);
-static gboolean gtk_hsv_focus                (GtkWidget          *widget,
-                                              GtkDirectionType    direction);
-static void     gtk_hsv_move                 (GtkHSV             *hsv,
-                                              GtkDirectionType    dir);
-
-static guint hsv_signals[LAST_SIGNAL];
-
-G_DEFINE_TYPE (GtkHSV, gtk_hsv, GTK_TYPE_WIDGET)
-
-/* Class initialization function for the HSV color selector */
-static void
-gtk_hsv_class_init (GtkHSVClass *class)
-{
-  GObjectClass   *gobject_class;
-  GtkWidgetClass *widget_class;
-  GtkHSVClass    *hsv_class;
-  GtkBindingSet  *binding_set;
-
-  gobject_class = (GObjectClass *) class;
-  widget_class = (GtkWidgetClass *) class;
-  hsv_class = GTK_HSV_CLASS (class);
-
-  widget_class->destroy = gtk_hsv_destroy;
-  widget_class->realize = gtk_hsv_realize;
-  widget_class->unrealize = gtk_hsv_unrealize;
-  widget_class->get_preferred_width = gtk_hsv_get_preferred_width;
-  widget_class->get_preferred_height = gtk_hsv_get_preferred_height;
-  widget_class->size_allocate = gtk_hsv_size_allocate;
-  widget_class->button_press_event = gtk_hsv_button_press;
-  widget_class->button_release_event = gtk_hsv_button_release;
-  widget_class->motion_notify_event = gtk_hsv_motion;
-  widget_class->draw = gtk_hsv_draw;
-  widget_class->focus = gtk_hsv_focus;
-  widget_class->grab_broken_event = gtk_hsv_grab_broken;
-
-  gtk_widget_class_set_accessible_role (widget_class, ATK_ROLE_COLOR_CHOOSER);
-
-  hsv_class->move = gtk_hsv_move;
-
-  hsv_signals[CHANGED] =
-    g_signal_new (I_("changed"),
-                  G_OBJECT_CLASS_TYPE (gobject_class),
-                  G_SIGNAL_RUN_FIRST,
-                  G_STRUCT_OFFSET (GtkHSVClass, changed),
-                  NULL, NULL,
-                  _gtk_marshal_VOID__VOID,
-                  G_TYPE_NONE, 0);
-
-  hsv_signals[MOVE] =
-    g_signal_new (I_("move"),
-                  G_OBJECT_CLASS_TYPE (gobject_class),
-                  G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
-                  G_STRUCT_OFFSET (GtkHSVClass, move),
-                  NULL, NULL,
-                  _gtk_marshal_VOID__ENUM,
-                  G_TYPE_NONE, 1,
-                  GTK_TYPE_DIRECTION_TYPE);
-
-  binding_set = gtk_binding_set_by_class (class);
-
-  gtk_binding_entry_add_signal (binding_set, GDK_KEY_Up, 0,
-                                "move", 1,
-                                G_TYPE_ENUM, GTK_DIR_UP);
-  gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Up, 0,
-                                "move", 1,
-                                G_TYPE_ENUM, GTK_DIR_UP);
-  gtk_binding_entry_add_signal (binding_set, GDK_KEY_Down, 0,
-                                "move", 1,
-                                G_TYPE_ENUM, GTK_DIR_DOWN);
-  gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Down, 0,
-                                "move", 1,
-                                G_TYPE_ENUM, GTK_DIR_DOWN);
-  gtk_binding_entry_add_signal (binding_set, GDK_KEY_Right, 0,
-                                "move", 1,
-                                G_TYPE_ENUM, GTK_DIR_RIGHT);
-  gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Right, 0,
-                                "move", 1,
-                                G_TYPE_ENUM, GTK_DIR_RIGHT);
-  gtk_binding_entry_add_signal (binding_set, GDK_KEY_Left, 0,
-                                "move", 1,
-                                G_TYPE_ENUM, GTK_DIR_LEFT);
-  gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Left, 0,
-                                "move", 1,
-                                G_TYPE_ENUM, GTK_DIR_LEFT);
-
-  g_type_class_add_private (gobject_class, sizeof (GtkHSVPrivate));
-}
-
-static void
-gtk_hsv_init (GtkHSV *hsv)
-{
-  GtkHSVPrivate *priv;
-
-  priv = G_TYPE_INSTANCE_GET_PRIVATE (hsv, GTK_TYPE_HSV, GtkHSVPrivate);
-
-  hsv->priv = priv;
-
-  gtk_widget_set_has_window (GTK_WIDGET (hsv), FALSE);
-  gtk_widget_set_can_focus (GTK_WIDGET (hsv), TRUE);
-
-  priv->h = 0.0;
-  priv->s = 0.0;
-  priv->v = 0.0;
-
-  priv->size = DEFAULT_SIZE;
-  priv->ring_width = DEFAULT_RING_WIDTH;
-}
-
-static void
-gtk_hsv_destroy (GtkWidget *widget)
-{
-  GTK_WIDGET_CLASS (gtk_hsv_parent_class)->destroy (widget);
-}
-
-static void
-gtk_hsv_realize (GtkWidget *widget)
-{
-  GtkHSV *hsv = GTK_HSV (widget);
-  GtkHSVPrivate *priv = hsv->priv;
-  GtkAllocation allocation;
-  GdkWindow *parent_window;
-  GdkWindowAttr attr;
-  int attr_mask;
-
-  gtk_widget_set_realized (widget, TRUE);
-
-  gtk_widget_get_allocation (widget, &allocation);
-
-  attr.window_type = GDK_WINDOW_CHILD;
-  attr.x = allocation.x;
-  attr.y = allocation.y;
-  attr.width = allocation.width;
-  attr.height = allocation.height;
-  attr.wclass = GDK_INPUT_ONLY;
-  attr.event_mask = gtk_widget_get_events (widget);
-  attr.event_mask |= (GDK_KEY_PRESS_MASK
-                      | GDK_BUTTON_PRESS_MASK
-                      | GDK_BUTTON_RELEASE_MASK
-                      | GDK_POINTER_MOTION_MASK
-                      | GDK_ENTER_NOTIFY_MASK
-                      | GDK_LEAVE_NOTIFY_MASK);
-  attr_mask = GDK_WA_X | GDK_WA_Y;
-
-  parent_window = gtk_widget_get_parent_window (widget);
-  gtk_widget_set_window (widget, parent_window);
-  g_object_ref (parent_window);
-
-  priv->window = gdk_window_new (parent_window, &attr, attr_mask);
-  gdk_window_set_user_data (priv->window, hsv);
-  gdk_window_show (priv->window);
-}
-
-static void
-gtk_hsv_unrealize (GtkWidget *widget)
-{
-  GtkHSV *hsv = GTK_HSV (widget);
-  GtkHSVPrivate *priv = hsv->priv;
-
-  gdk_window_set_user_data (priv->window, NULL);
-  gdk_window_destroy (priv->window);
-  priv->window = NULL;
-
-  GTK_WIDGET_CLASS (gtk_hsv_parent_class)->unrealize (widget);
-}
-
-static void
-gtk_hsv_get_preferred_width (GtkWidget *widget,
-                             gint      *minimum,
-                             gint      *natural)
-{
-  GtkHSV *hsv = GTK_HSV (widget);
-  GtkHSVPrivate *priv = hsv->priv;
-  gint focus_width;
-  gint focus_pad;
-
-  gtk_widget_style_get (widget,
-                        "focus-line-width", &focus_width,
-                        "focus-padding", &focus_pad,
-                        NULL);
-
-  *minimum = priv->size + 2 * (focus_width + focus_pad);
-  *natural = priv->size + 2 * (focus_width + focus_pad);
-}
-
-static void
-gtk_hsv_get_preferred_height (GtkWidget *widget,
-                              gint      *minimum,
-                              gint      *natural)
-{
-  GtkHSV *hsv = GTK_HSV (widget);
-  GtkHSVPrivate *priv = hsv->priv;
-  gint focus_width;
-  gint focus_pad;
-
-  gtk_widget_style_get (widget,
-                        "focus-line-width", &focus_width,
-                        "focus-padding", &focus_pad,
-                        NULL);
-
-  *minimum = priv->size + 2 * (focus_width + focus_pad);
-  *natural = priv->size + 2 * (focus_width + focus_pad);
-}
-
-static void
-gtk_hsv_size_allocate (GtkWidget     *widget,
-                       GtkAllocation *allocation)
-{
-  GtkHSV *hsv = GTK_HSV (widget);
-  GtkHSVPrivate *priv = hsv->priv;
-
-  gtk_widget_set_allocation (widget, allocation);
-
-  if (gtk_widget_get_realized (widget))
-    gdk_window_move_resize (priv->window,
-                            allocation->x,
-                            allocation->y,
-                            allocation->width,
-                            allocation->height);
-}
-
-
-/* Utility functions */
-
-#define INTENSITY(r, g, b) ((r) * 0.30 + (g) * 0.59 + (b) * 0.11)
-
-/* Converts from HSV to RGB */
-static void
-hsv_to_rgb (gdouble *h,
-            gdouble *s,
-            gdouble *v)
-{
-  gdouble hue, saturation, value;
-  gdouble f, p, q, t;
-
-  if (*s == 0.0)
-    {
-      *h = *v;
-      *s = *v;
-      *v = *v; /* heh */
-    }
-  else
-    {
-      hue = *h * 6.0;
-      saturation = *s;
-      value = *v;
-
-      if (hue == 6.0)
-        hue = 0.0;
-
-      f = hue - (int) hue;
-      p = value * (1.0 - saturation);
-      q = value * (1.0 - saturation * f);
-      t = value * (1.0 - saturation * (1.0 - f));
-
-      switch ((int) hue)
-        {
-        case 0:
-          *h = value;
-          *s = t;
-          *v = p;
-          break;
-
-        case 1:
-          *h = q;
-          *s = value;
-          *v = p;
-          break;
-
-        case 2:
-          *h = p;
-          *s = value;
-          *v = t;
-          break;
-
-        case 3:
-          *h = p;
-          *s = q;
-          *v = value;
-          break;
-
-        case 4:
-          *h = t;
-          *s = p;
-          *v = value;
-          break;
-
-        case 5:
-          *h = value;
-          *s = p;
-          *v = q;
-          break;
-
-        default:
-          g_assert_not_reached ();
-        }
-    }
-}
-
-/* Converts from RGB to HSV */
-static void
-rgb_to_hsv (gdouble *r,
-            gdouble *g,
-            gdouble *b)
-{
-  gdouble red, green, blue;
-  gdouble h, s, v;
-  gdouble min, max;
-  gdouble delta;
-
-  red = *r;
-  green = *g;
-  blue = *b;
-
-  h = 0.0;
-
-  if (red > green)
-    {
-      if (red > blue)
-        max = red;
-      else
-        max = blue;
-
-      if (green < blue)
-        min = green;
-      else
-        min = blue;
-    }
-  else
-    {
-      if (green > blue)
-        max = green;
-      else
-        max = blue;
-
-      if (red < blue)
-        min = red;
-      else
-        min = blue;
-    }
-
-  v = max;
-
-  if (max != 0.0)
-    s = (max - min) / max;
-  else
-    s = 0.0;
-
-  if (s == 0.0)
-    h = 0.0;
-  else
-    {
-      delta = max - min;
-
-      if (red == max)
-        h = (green - blue) / delta;
-      else if (green == max)
-        h = 2 + (blue - red) / delta;
-      else if (blue == max)
-        h = 4 + (red - green) / delta;
-
-      h /= 6.0;
-
-      if (h < 0.0)
-        h += 1.0;
-      else if (h > 1.0)
-        h -= 1.0;
-    }
-
-  *r = h;
-  *g = s;
-  *b = v;
-}
-
-/* Computes the vertices of the saturation/value triangle */
-static void
-compute_triangle (GtkHSV *hsv,
-                  gint   *hx,
-                  gint   *hy,
-                  gint   *sx,
-                  gint   *sy,
-                  gint   *vx,
-                  gint   *vy)
-{
-  GtkHSVPrivate *priv = hsv->priv;
-  GtkWidget *widget = GTK_WIDGET (hsv);
-  gdouble center_x;
-  gdouble center_y;
-  gdouble inner, outer;
-  gdouble angle;
-
-  center_x = gtk_widget_get_allocated_width (widget) / 2.0;
-  center_y = gtk_widget_get_allocated_height (widget) / 2.0;
-  outer = priv->size / 2.0;
-  inner = outer - priv->ring_width;
-  angle = priv->h * 2.0 * G_PI;
-
-  *hx = floor (center_x + cos (angle) * inner + 0.5);
-  *hy = floor (center_y - sin (angle) * inner + 0.5);
-  *sx = floor (center_x + cos (angle + 2.0 * G_PI / 3.0) * inner + 0.5);
-  *sy = floor (center_y - sin (angle + 2.0 * G_PI / 3.0) * inner + 0.5);
-  *vx = floor (center_x + cos (angle + 4.0 * G_PI / 3.0) * inner + 0.5);
-  *vy = floor (center_y - sin (angle + 4.0 * G_PI / 3.0) * inner + 0.5);
-}
-
-/* Computes whether a point is inside the hue ring */
-static gboolean
-is_in_ring (GtkHSV *hsv,
-            gdouble x,
-            gdouble y)
-{
-  GtkHSVPrivate *priv = hsv->priv;
-  GtkWidget *widget = GTK_WIDGET (hsv);
-  gdouble dx, dy, dist;
-  gdouble center_x;
-  gdouble center_y;
-  gdouble inner, outer;
-
-  center_x = gtk_widget_get_allocated_width (widget) / 2.0;
-  center_y = gtk_widget_get_allocated_height (widget) / 2.0;
-  outer = priv->size / 2.0;
-  inner = outer - priv->ring_width;
-
-  dx = x - center_x;
-  dy = center_y - y;
-  dist = dx * dx + dy * dy;
-
-  return (dist >= inner * inner && dist <= outer * outer);
-}
-
-/* Computes a saturation/value pair based on the mouse coordinates */
-static void
-compute_sv (GtkHSV  *hsv,
-            gdouble  x,
-            gdouble  y,
-            gdouble *s,
-            gdouble *v)
-{
-  GtkWidget *widget = GTK_WIDGET (hsv);
-  int ihx, ihy, isx, isy, ivx, ivy;
-  double hx, hy, sx, sy, vx, vy;
-  double center_x;
-  double center_y;
-
-  compute_triangle (hsv, &ihx, &ihy, &isx, &isy, &ivx, &ivy);
-  center_x = gtk_widget_get_allocated_width (widget) / 2.0;
-  center_y = gtk_widget_get_allocated_height (widget) / 2.0;
-  hx = ihx - center_x;
-  hy = center_y - ihy;
-  sx = isx - center_x;
-  sy = center_y - isy;
-  vx = ivx - center_x;
-  vy = center_y - ivy;
-  x -= center_x;
-  y = center_y - y;
-  
-  if (vx * (x - sx) + vy * (y - sy) < 0.0)
-    {
-      *s = 1.0;
-      *v = (((x - sx) * (hx - sx) + (y - sy) * (hy-sy))
-            / ((hx - sx) * (hx - sx) + (hy - sy) * (hy - sy)));
-      
-      if (*v < 0.0)
-        *v = 0.0;
-      else if (*v > 1.0)
-        *v = 1.0;
-    }
-  else if (hx * (x - sx) + hy * (y - sy) < 0.0)
-    {
-      *s = 0.0;
-      *v = (((x - sx) * (vx - sx) + (y - sy) * (vy - sy))
-            / ((vx - sx) * (vx - sx) + (vy - sy) * (vy - sy)));
-      
-      if (*v < 0.0)
-        *v = 0.0;
-      else if (*v > 1.0)
-        *v = 1.0;
-    }
-  else if (sx * (x - hx) + sy * (y - hy) < 0.0)
-    {
-      *v = 1.0;
-      *s = (((x - vx) * (hx - vx) + (y - vy) * (hy - vy)) /
-            ((hx - vx) * (hx - vx) + (hy - vy) * (hy - vy)));
-      
-      if (*s < 0.0)
-        *s = 0.0;
-      else if (*s > 1.0)
-        *s = 1.0;
-    }
-  else
-    {
-      *v = (((x - sx) * (hy - vy) - (y - sy) * (hx - vx))
-            / ((vx - sx) * (hy - vy) - (vy - sy) * (hx - vx)));
-      
-      if (*v<= 0.0)
-        {
-          *v = 0.0;
-          *s = 0.0;
-        }
-      else
-        {
-          if (*v > 1.0)
-            *v = 1.0;
-
-          if (fabs (hy - vy) < fabs (hx - vx))
-            *s = (x - sx - *v * (vx - sx)) / (*v * (hx - vx));
-          else
-            *s = (y - sy - *v * (vy - sy)) / (*v * (hy - vy));
-
-          if (*s < 0.0)
-            *s = 0.0;
-          else if (*s > 1.0)
-            *s = 1.0;
-        }
-    }
-}
-
-/* Computes whether a point is inside the saturation/value triangle */
-static gboolean
-is_in_triangle (GtkHSV *hsv,
-                gdouble x,
-                gdouble y)
-{
-  int hx, hy, sx, sy, vx, vy;
-  double det, s, v;
-  
-  compute_triangle (hsv, &hx, &hy, &sx, &sy, &vx, &vy);
-  
-  det = (vx - sx) * (hy - sy) - (vy - sy) * (hx - sx);
-  
-  s = ((x - sx) * (hy - sy) - (y - sy) * (hx - sx)) / det;
-  v = ((vx - sx) * (y - sy) - (vy - sy) * (x - sx)) / det;
-  
-  return (s >= 0.0 && v >= 0.0 && s + v <= 1.0);
-}
-
-/* Computes a value based on the mouse coordinates */
-static double
-compute_v (GtkHSV *hsv,
-           gdouble x,
-           gdouble y)
-{
-  GtkWidget *widget = GTK_WIDGET (hsv);
-  double center_x;
-  double center_y;
-  double dx, dy;
-  double angle;
-
-  center_x = gtk_widget_get_allocated_width (widget) / 2.0;
-  center_y = gtk_widget_get_allocated_height (widget) / 2.0;
-  dx = x - center_x;
-  dy = center_y - y;
-
-  angle = atan2 (dy, dx);
-  if (angle < 0.0)
-    angle += 2.0 * G_PI;
-
-  return angle / (2.0 * G_PI);
-}
-
-/* Event handlers */
-
-static void
-set_cross_grab (GtkHSV    *hsv,
-                GdkDevice *device,
-                guint32    time)
-{
-  GtkHSVPrivate *priv = hsv->priv;
-  GdkCursor *cursor;
-
-  cursor = gdk_cursor_new_for_display (gtk_widget_get_display (GTK_WIDGET (hsv)),
-                                       GDK_CROSSHAIR);
-  gdk_device_grab (device,
-                   priv->window,
-                   GDK_OWNERSHIP_NONE,
-                   FALSE,
-                   GDK_POINTER_MOTION_MASK
-                    | GDK_POINTER_MOTION_HINT_MASK
-                    | GDK_BUTTON_RELEASE_MASK,
-                   cursor,
-                   time);
-  g_object_unref (cursor);
-}
-
-static gboolean
-gtk_hsv_grab_broken (GtkWidget          *widget,
-                     GdkEventGrabBroken *event)
-{
-  GtkHSV *hsv = GTK_HSV (widget);
-  GtkHSVPrivate *priv = hsv->priv;
-
-  priv->mode = DRAG_NONE;
-
-  return TRUE;
-}
-
-static gint
-gtk_hsv_button_press (GtkWidget      *widget,
-                      GdkEventButton *event)
-{
-  GtkHSV *hsv = GTK_HSV (widget);
-  GtkHSVPrivate *priv = hsv->priv;
-  double x, y;
-
-  if (priv->mode != DRAG_NONE || event->button != GDK_BUTTON_PRIMARY)
-    return FALSE;
-
-  x = event->x;
-  y = event->y;
-
-  if (is_in_ring (hsv, x, y))
-    {
-      priv->mode = DRAG_H;
-      set_cross_grab (hsv, gdk_event_get_device ((GdkEvent *) event), event->time);
-
-      gtk_hsv_set_color (hsv,
-                         compute_v (hsv, x, y),
-                         priv->s,
-                         priv->v);
-
-      gtk_widget_grab_focus (widget);
-      priv->focus_on_ring = TRUE;
-
-      return TRUE;
-    }
-
-  if (is_in_triangle (hsv, x, y))
-    {
-      gdouble s, v;
-
-      priv->mode = DRAG_SV;
-      set_cross_grab (hsv, gdk_event_get_device ((GdkEvent *) event), event->time);
-
-      compute_sv (hsv, x, y, &s, &v);
-      gtk_hsv_set_color (hsv, priv->h, s, v);
-
-      gtk_widget_grab_focus (widget);
-      priv->focus_on_ring = FALSE;
-
-      return TRUE;
-    }
-
-  return FALSE;
-}
-
-static gint
-gtk_hsv_button_release (GtkWidget      *widget,
-                        GdkEventButton *event)
-{
-  GtkHSV *hsv = GTK_HSV (widget);
-  GtkHSVPrivate *priv = hsv->priv;
-  DragMode mode;
-  gdouble x, y;
-
-  if (priv->mode == DRAG_NONE || event->button != GDK_BUTTON_PRIMARY)
-    return FALSE;
-
-  /* Set the drag mode to DRAG_NONE so that signal handlers for "catched"
-   * can see that this is the final color state.
-   */
-  mode = priv->mode;
-  priv->mode = DRAG_NONE;
-
-  x = event->x;
-  y = event->y;
-
-  if (mode == DRAG_H)
-    {
-      gtk_hsv_set_color (hsv, compute_v (hsv, x, y), priv->s, priv->v);
-    }
-  else if (mode == DRAG_SV)
-    {
-      gdouble s, v;
-
-      compute_sv (hsv, x, y, &s, &v);
-      gtk_hsv_set_color (hsv, priv->h, s, v);
-    }
-  else
-    {
-      g_assert_not_reached ();
-    }
-
-  gdk_device_ungrab (gdk_event_get_device ((GdkEvent *) event), event->time);
-
-  return TRUE;
-}
-
-static gint
-gtk_hsv_motion (GtkWidget      *widget,
-                GdkEventMotion *event)
-{
-  GtkHSV *hsv = GTK_HSV (widget);
-  GtkHSVPrivate *priv = hsv->priv;
-  gdouble x, y;
-
-  if (priv->mode == DRAG_NONE)
-    return FALSE;
-
-  gdk_event_request_motions (event);
-  x = event->x;
-  y = event->y;
-
-  if (priv->mode == DRAG_H)
-    {
-      gtk_hsv_set_color (hsv, compute_v (hsv, x, y), priv->s, priv->v);
-      return TRUE;
-    }
-  else if (priv->mode == DRAG_SV)
-    {
-      gdouble s, v;
-
-      compute_sv (hsv, x, y, &s, &v);
-      gtk_hsv_set_color (hsv, priv->h, s, v);
-      return TRUE;
-    }
-
-  g_assert_not_reached ();
-
-  return FALSE;
-}
-
-
-/* Redrawing */
-
-/* Paints the hue ring */
-static void
-paint_ring (GtkHSV  *hsv,
-            cairo_t *cr)
-{
-  GtkHSVPrivate *priv = hsv->priv;
-  GtkWidget *widget = GTK_WIDGET (hsv);
-  int xx, yy, width, height;
-  gdouble dx, dy, dist;
-  gdouble center_x;
-  gdouble center_y;
-  gdouble inner, outer;
-  guint32 *buf, *p;
-  gdouble angle;
-  gdouble hue;
-  gdouble r, g, b;
-  cairo_surface_t *source;
-  cairo_t *source_cr;
-  gint stride;
-
-  width = gtk_widget_get_allocated_width (widget);
-  height = gtk_widget_get_allocated_height (widget);
-
-  center_x = width / 2.0;
-  center_y = height / 2.0;
-
-  outer = priv->size / 2.0;
-  inner = outer - priv->ring_width;
-
-  /* Create an image initialized with the ring colors */
-
-  stride = cairo_format_stride_for_width (CAIRO_FORMAT_RGB24, width);
-  buf = g_new (guint32, height * stride / 4);
-
-  for (yy = 0; yy < height; yy++)
-    {
-      p = buf + yy * width;
-
-      dy = -(yy - center_y);
-
-      for (xx = 0; xx < width; xx++)
-        {
-          dx = xx - center_x;
-
-          dist = dx * dx + dy * dy;
-          if (dist < ((inner-1) * (inner-1)) || dist > ((outer+1) * (outer+1)))
-            {
-              *p++ = 0;
-              continue;
-            }
-
-          angle = atan2 (dy, dx);
-          if (angle < 0.0)
-            angle += 2.0 * G_PI;
-
-          hue = angle / (2.0 * G_PI);
-
-          r = hue;
-          g = 1.0;
-          b = 1.0;
-          hsv_to_rgb (&r, &g, &b);
-
-          *p++ = (((int)floor (r * 255 + 0.5) << 16) |
-                  ((int)floor (g * 255 + 0.5) << 8) |
-                  (int)floor (b * 255 + 0.5));
-        }
-    }
-
-  source = cairo_image_surface_create_for_data ((unsigned char *)buf,
-                                                CAIRO_FORMAT_RGB24,
-                                                width, height, stride);
-
-  /* Now draw the value marker onto the source image, so that it
-   * will get properly clipped at the edges of the ring
-   */
-  source_cr = cairo_create (source);
-  
-  r = priv->h;
-  g = 1.0;
-  b = 1.0;
-  hsv_to_rgb (&r, &g, &b);
-  
-  if (INTENSITY (r, g, b) > 0.5)
-    cairo_set_source_rgb (source_cr, 0., 0., 0.);
-  else
-    cairo_set_source_rgb (source_cr, 1., 1., 1.);
-
-  cairo_move_to (source_cr, center_x, center_y);
-  cairo_line_to (source_cr,
-                 center_x + cos (priv->h * 2.0 * G_PI) * priv->size / 2,
-                 center_y - sin (priv->h * 2.0 * G_PI) * priv->size / 2);
-  cairo_stroke (source_cr);
-  cairo_destroy (source_cr);
-
-  /* Draw the ring using the source image */
-
-  cairo_save (cr);
-    
-  cairo_set_source_surface (cr, source, 0, 0);
-  cairo_surface_destroy (source);
-
-  cairo_set_line_width (cr, priv->ring_width);
-  cairo_new_path (cr);
-  cairo_arc (cr,
-             center_x, center_y,
-             priv->size / 2. - priv->ring_width / 2.,
-             0, 2 * G_PI);
-  cairo_stroke (cr);
-  
-  cairo_restore (cr);
-  
-  g_free (buf);
-}
-
-/* Converts an HSV triplet to an integer RGB triplet */
-static void
-get_color (gdouble h,
-           gdouble s,
-           gdouble v,
-           gint   *r,
-           gint   *g,
-           gint   *b)
-{
-  hsv_to_rgb (&h, &s, &v);
-  
-  *r = floor (h * 255 + 0.5);
-  *g = floor (s * 255 + 0.5);
-  *b = floor (v * 255 + 0.5);
-}
-
-#define SWAP(a, b, t) ((t) = (a), (a) = (b), (b) = (t))
-
-#define LERP(a, b, v1, v2, i) (((v2) - (v1) != 0)                                       \
-                               ? ((a) + ((b) - (a)) * ((i) - (v1)) / ((v2) - (v1)))     \
-                               : (a))
-
-/* Number of pixels we extend out from the edges when creating
- * color source to avoid artifacts
- */
-#define PAD 3
-
-/* Paints the HSV triangle */
-static void
-paint_triangle (GtkHSV   *hsv,
-                cairo_t  *cr,
-                gboolean  draw_focus)
-{
-  GtkHSVPrivate *priv = hsv->priv;
-  GtkWidget *widget = GTK_WIDGET (hsv);
-  gint hx, hy, sx, sy, vx, vy; /* HSV vertices */
-  gint x1, y1, r1, g1, b1; /* First vertex in scanline order */
-  gint x2, y2, r2, g2, b2; /* Second vertex */
-  gint x3, y3, r3, g3, b3; /* Third vertex */
-  gint t;
-  guint32 *buf, *p, c;
-  gint xl, xr, rl, rr, gl, gr, bl, br; /* Scanline data */
-  gint xx, yy;
-  gint x_interp, y_interp;
-  gint x_start, x_end;
-  cairo_surface_t *source;
-  gdouble r, g, b;
-  gint stride;
-  int width, height;
-  GtkStyleContext *context;
-
-  priv = hsv->priv;
-  width = gtk_widget_get_allocated_width (widget); 
-  height = gtk_widget_get_allocated_height (widget); 
-  /* Compute triangle's vertices */
-  
-  compute_triangle (hsv, &hx, &hy, &sx, &sy, &vx, &vy);
-  
-  x1 = hx;
-  y1 = hy;
-  get_color (priv->h, 1.0, 1.0, &r1, &g1, &b1);
-
-  x2 = sx;
-  y2 = sy;
-  get_color (priv->h, 1.0, 0.0, &r2, &g2, &b2);
-
-  x3 = vx;
-  y3 = vy;
-  get_color (priv->h, 0.0, 1.0, &r3, &g3, &b3);
-
-  if (y2 > y3)
-    {
-      SWAP (x2, x3, t);
-      SWAP (y2, y3, t);
-      SWAP (r2, r3, t);
-      SWAP (g2, g3, t);
-      SWAP (b2, b3, t);
-    }
-
-  if (y1 > y3)
-    {
-      SWAP (x1, x3, t);
-      SWAP (y1, y3, t);
-      SWAP (r1, r3, t);
-      SWAP (g1, g3, t);
-      SWAP (b1, b3, t);
-    }
-
-  if (y1 > y2)
-    {
-      SWAP (x1, x2, t);
-      SWAP (y1, y2, t);
-      SWAP (r1, r2, t);
-      SWAP (g1, g2, t);
-      SWAP (b1, b2, t);
-    }
-
-  /* Shade the triangle */
-
-  stride = cairo_format_stride_for_width (CAIRO_FORMAT_RGB24, width);
-  buf = g_new (guint32, height * stride / 4);
-
-  for (yy = 0; yy < height; yy++)
-    {
-      p = buf + yy * width;
-
-      if (yy >= y1 - PAD && yy < y3 + PAD) {
-        y_interp = CLAMP (yy, y1, y3);
-
-        if (y_interp < y2)
-          {
-            xl = LERP (x1, x2, y1, y2, y_interp);
-
-            rl = LERP (r1, r2, y1, y2, y_interp);
-            gl = LERP (g1, g2, y1, y2, y_interp);
-            bl = LERP (b1, b2, y1, y2, y_interp);
-          }
-        else
-          {
-            xl = LERP (x2, x3, y2, y3, y_interp);
-
-            rl = LERP (r2, r3, y2, y3, y_interp);
-            gl = LERP (g2, g3, y2, y3, y_interp);
-            bl = LERP (b2, b3, y2, y3, y_interp);
-          }
-
-        xr = LERP (x1, x3, y1, y3, y_interp);
-
-        rr = LERP (r1, r3, y1, y3, y_interp);
-        gr = LERP (g1, g3, y1, y3, y_interp);
-        br = LERP (b1, b3, y1, y3, y_interp);
-
-        if (xl > xr)
-          {
-            SWAP (xl, xr, t);
-            SWAP (rl, rr, t);
-            SWAP (gl, gr, t);
-            SWAP (bl, br, t);
-          }
-
-        x_start = MAX (xl - PAD, 0);
-        x_end = MIN (xr + PAD, width);
-        x_start = MIN (x_start, x_end);
-
-        c = (rl << 16) | (gl << 8) | bl;
-
-        for (xx = 0; xx < x_start; xx++)
-          *p++ = c;
-
-        for (; xx < x_end; xx++)
-          {
-            x_interp = CLAMP (xx, xl, xr);
-
-            *p++ = ((LERP (rl, rr, xl, xr, x_interp) << 16) |
-                    (LERP (gl, gr, xl, xr, x_interp) << 8) |
-                    LERP (bl, br, xl, xr, x_interp));
-          }
-
-        c = (rr << 16) | (gr << 8) | br;
-
-        for (; xx < width; xx++)
-          *p++ = c;
-      }
-    }
-
-  source = cairo_image_surface_create_for_data ((unsigned char *)buf,
-                                                CAIRO_FORMAT_RGB24,
-                                                width, height, stride);
-  
-  /* Draw a triangle with the image as a source */
-
-  cairo_set_source_surface (cr, source, 0, 0);
-  cairo_surface_destroy (source);
-  
-  cairo_move_to (cr, x1, y1);
-  cairo_line_to (cr, x2, y2);
-  cairo_line_to (cr, x3, y3);
-  cairo_close_path (cr);
-  cairo_fill (cr);
-  
-  g_free (buf);
-  
-  /* Draw value marker */
-  
-  xx = floor (sx + (vx - sx) * priv->v + (hx - vx) * priv->s * priv->v + 0.5);
-  yy = floor (sy + (vy - sy) * priv->v + (hy - vy) * priv->s * priv->v + 0.5);
-  
-  r = priv->h;
-  g = priv->s;
-  b = priv->v;
-  hsv_to_rgb (&r, &g, &b);
-
-  context = gtk_widget_get_style_context (widget);
-
-  gtk_style_context_save (context);
-
-  if (INTENSITY (r, g, b) > 0.5)
-    {
-      gtk_style_context_add_class (context, "light-area-focus");
-      cairo_set_source_rgb (cr, 0., 0., 0.);
-    }
-  else
-    {
-      gtk_style_context_add_class (context, "dark-area-focus");
-      cairo_set_source_rgb (cr, 1., 1., 1.);
-    }
-
-#define RADIUS 4
-#define FOCUS_RADIUS 6
-
-  cairo_new_path (cr);
-  cairo_arc (cr, xx, yy, RADIUS, 0, 2 * G_PI);
-  cairo_stroke (cr);
-  
-  /* Draw focus outline */
-
-  if (draw_focus && !priv->focus_on_ring)
-    {
-      gint focus_width;
-      gint focus_pad;
-
-      gtk_widget_style_get (widget,
-                            "focus-line-width", &focus_width,
-                            "focus-padding", &focus_pad,
-                            NULL);
-
-      gtk_render_focus (context, cr,
-                        xx - FOCUS_RADIUS - focus_width - focus_pad,
-                        yy - FOCUS_RADIUS - focus_width - focus_pad,
-                        2 * (FOCUS_RADIUS + focus_width + focus_pad),
-                        2 * (FOCUS_RADIUS + focus_width + focus_pad));
-    }
-
-  gtk_style_context_restore (context);
-}
-
-/* Paints the contents of the HSV color selector */
-static gboolean
-gtk_hsv_draw (GtkWidget *widget,
-              cairo_t   *cr)
-{
-  GtkHSV *hsv = GTK_HSV (widget);
-  GtkHSVPrivate *priv = hsv->priv;
-  gboolean draw_focus;
-
-  draw_focus = gtk_widget_has_visible_focus (widget);
-
-  paint_ring (hsv, cr);
-  paint_triangle (hsv, cr, draw_focus);
-
-
-  if (draw_focus && priv->focus_on_ring)
-    {
-      GtkStyleContext *context;
-
-      context = gtk_widget_get_style_context (widget);
-
-      gtk_render_focus (context, cr, 0, 0,
-                        gtk_widget_get_allocated_width (widget),
-                        gtk_widget_get_allocated_height (widget));
-    }
-
-  return FALSE;
-}
-
-static gboolean
-gtk_hsv_focus (GtkWidget       *widget,
-               GtkDirectionType dir)
-{
-  GtkHSV *hsv = GTK_HSV (widget);
-  GtkHSVPrivate *priv = hsv->priv;
-
-  if (!gtk_widget_has_focus (widget))
-    {
-      if (dir == GTK_DIR_TAB_BACKWARD)
-        priv->focus_on_ring = FALSE;
-      else
-        priv->focus_on_ring = TRUE;
-
-      gtk_widget_grab_focus (GTK_WIDGET (hsv));
-      return TRUE;
-    }
-  
-  switch (dir)
-    {
-    case GTK_DIR_UP:
-      if (priv->focus_on_ring)
-        return FALSE;
-      else
-        priv->focus_on_ring = TRUE;
-      break;
-
-    case GTK_DIR_DOWN:
-      if (priv->focus_on_ring)
-        priv->focus_on_ring = FALSE;
-      else
-        return FALSE;
-      break;
-
-    case GTK_DIR_LEFT:
-    case GTK_DIR_TAB_BACKWARD:
-      if (priv->focus_on_ring)
-        return FALSE;
-      else
-        priv->focus_on_ring = TRUE;
-      break;
-
-    case GTK_DIR_RIGHT:
-    case GTK_DIR_TAB_FORWARD:
-      if (priv->focus_on_ring)
-        priv->focus_on_ring = FALSE;
-      else
-        return FALSE;
-      break;
-    }
-
-  gtk_widget_queue_draw (GTK_WIDGET (hsv));
-
-  return TRUE;
-}
-
-/**
- * gtk_hsv_new:
- *
- * Creates a new HSV color selector.
- *
- * Return value: A newly-created HSV color selector.
- *
- * Since: 2.14
- */
-GtkWidget*
-gtk_hsv_new (void)
-{
-  return g_object_new (GTK_TYPE_HSV, NULL);
-}
-
-/**
- * gtk_hsv_set_color:
- * @hsv: An HSV color selector
- * @h: Hue
- * @s: Saturation
- * @v: Value
- *
- * Sets the current color in an HSV color selector.
- * Color component values must be in the [0.0, 1.0] range.
- *
- * Since: 2.14
- */
-void
-gtk_hsv_set_color (GtkHSV *hsv,
-                   gdouble h,
-                   gdouble s,
-                   gdouble v)
-{
-  GtkHSVPrivate *priv;
-
-  g_return_if_fail (GTK_IS_HSV (hsv));
-  g_return_if_fail (h >= 0.0 && h <= 1.0);
-  g_return_if_fail (s >= 0.0 && s <= 1.0);
-  g_return_if_fail (v >= 0.0 && v <= 1.0);
-
-  priv = hsv->priv;
-
-  priv->h = h;
-  priv->s = s;
-  priv->v = v;
-  
-  g_signal_emit (hsv, hsv_signals[CHANGED], 0);
-  
-  gtk_widget_queue_draw (GTK_WIDGET (hsv));
-}
-
-/**
- * gtk_hsv_get_color:
- * @hsv: An HSV color selector
- * @h: (out): Return value for the hue
- * @s: (out): Return value for the saturation
- * @v: (out): Return value for the value
- *
- * Queries the current color in an HSV color selector.
- * Returned values will be in the [0.0, 1.0] range.
- *
- * Since: 2.14
- */
-void
-gtk_hsv_get_color (GtkHSV *hsv,
-                   double *h,
-                   double *s,
-                   double *v)
-{
-  GtkHSVPrivate *priv;
-
-  g_return_if_fail (GTK_IS_HSV (hsv));
-
-  priv = hsv->priv;
-
-  if (h)
-    *h = priv->h;
-
-  if (s)
-    *s = priv->s;
-
-  if (v)
-    *v = priv->v;
-}
-
-/**
- * gtk_hsv_set_metrics:
- * @hsv: An HSV color selector
- * @size: Diameter for the hue ring
- * @ring_width: Width of the hue ring
- *
- * Sets the size and ring width of an HSV color selector.
- *
- * Since: 2.14
- */
-void
-gtk_hsv_set_metrics (GtkHSV *hsv,
-                     gint    size,
-                     gint    ring_width)
-{
-  GtkHSVPrivate *priv;
-  int same_size;
-
-  g_return_if_fail (GTK_IS_HSV (hsv));
-  g_return_if_fail (size > 0);
-  g_return_if_fail (ring_width > 0);
-  g_return_if_fail (2 * ring_width + 1 <= size);
-
-  priv = hsv->priv;
-
-  same_size = (priv->size == size);
-
-  priv->size = size;
-  priv->ring_width = ring_width;
-  
-  if (same_size)
-    gtk_widget_queue_draw (GTK_WIDGET (hsv));
-  else
-    gtk_widget_queue_resize (GTK_WIDGET (hsv));
-}
-
-/**
- * gtk_hsv_get_metrics:
- * @hsv: An HSV color selector
- * @size: (out): Return value for the diameter of the hue ring
- * @ring_width: (out): Return value for the width of the hue ring
- *
- * Queries the size and ring width of an HSV color selector.
- *
- * Since: 2.14
- */
-void
-gtk_hsv_get_metrics (GtkHSV *hsv,
-                     gint   *size,
-                     gint   *ring_width)
-{
-  GtkHSVPrivate *priv;
-
-  g_return_if_fail (GTK_IS_HSV (hsv));
-
-  priv = hsv->priv;
-
-  if (size)
-    *size = priv->size;
-  
-  if (ring_width)
-    *ring_width = priv->ring_width;
-}
-
-/**
- * gtk_hsv_is_adjusting:
- * @hsv: A #GtkHSV 
- *
- * An HSV color selector can be said to be adjusting if multiple rapid
- * changes are being made to its value, for example, when the user is 
- * adjusting the value with the mouse. This function queries whether 
- * the HSV color selector is being adjusted or not.
- *
- * Return value: %TRUE if clients can ignore changes to the color value,
- *     since they may be transitory, or %FALSE if they should consider
- *     the color value status to be final.
- *
- * Since: 2.14
- */
-gboolean
-gtk_hsv_is_adjusting (GtkHSV *hsv)
-{
-  GtkHSVPrivate *priv;
-
-  g_return_val_if_fail (GTK_IS_HSV (hsv), FALSE);
-
-  priv = hsv->priv;
-
-  return priv->mode != DRAG_NONE;
-}
-
-/**
- * gtk_hsv_to_rgb:
- * @h: Hue
- * @s: Saturation
- * @v: Value
- * @r: (out): Return value for the red component
- * @g: (out): Return value for the green component
- * @b: (out): Return value for the blue component
- *
- * Converts a color from HSV space to RGB.
- * Input values must be in the [0.0, 1.0] range; 
- * output values will be in the same range.
- *
- * Since: 2.14
- */
-void
-gtk_hsv_to_rgb (gdouble  h,
-                gdouble  s,
-                gdouble  v,
-                gdouble *r,
-                gdouble *g,
-                gdouble *b)
-{
-  g_return_if_fail (h >= 0.0 && h <= 1.0);
-  g_return_if_fail (s >= 0.0 && s <= 1.0);
-  g_return_if_fail (v >= 0.0 && v <= 1.0);
-  
-  hsv_to_rgb (&h, &s, &v);
-  
-  if (r)
-    *r = h;
-  
-  if (g)
-    *g = s;
-  
-  if (b)
-    *b = v;
-}
-
-/**
- * gtk_rgb_to_hsv:
- * @r: Red
- * @g: Green
- * @b: Blue
- * @h: (out): Return value for the hue component
- * @s: (out): Return value for the saturation component
- * @v: (out): Return value for the value component
- *
- * Converts a color from RGB space to HSV.
- * Input values must be in the [0.0, 1.0] range;
- * output values will be in the same range.
- *
- * Since: 2.14
- */
-void
-gtk_rgb_to_hsv (gdouble  r,
-                gdouble  g,
-                gdouble  b,
-                gdouble *h,
-                gdouble *s,
-                gdouble *v)
-{
-  g_return_if_fail (r >= 0.0 && r <= 1.0);
-  g_return_if_fail (g >= 0.0 && g <= 1.0);
-  g_return_if_fail (b >= 0.0 && b <= 1.0);
-  
-  rgb_to_hsv (&r, &g, &b);
-  
-  if (h)
-    *h = r;
-  
-  if (s)
-    *s = g;
-  
-  if (v)
-    *v = b;
-}
-
-static void
-gtk_hsv_move (GtkHSV          *hsv,
-              GtkDirectionType dir)
-{
-  GtkHSVPrivate *priv = hsv->priv;
-  gdouble hue, sat, val;
-  gint hx, hy, sx, sy, vx, vy; /* HSV vertices */
-  gint x, y; /* position in triangle */
-
-  hue = priv->h;
-  sat = priv->s;
-  val = priv->v;
-
-  compute_triangle (hsv, &hx, &hy, &sx, &sy, &vx, &vy);
-
-  x = floor (sx + (vx - sx) * priv->v + (hx - vx) * priv->s * priv->v + 0.5);
-  y = floor (sy + (vy - sy) * priv->v + (hy - vy) * priv->s * priv->v + 0.5);
-
-#define HUE_DELTA 0.002
-  switch (dir)
-    {
-    case GTK_DIR_UP:
-      if (priv->focus_on_ring)
-        hue += HUE_DELTA;
-      else
-        {
-          y -= 1;
-          compute_sv (hsv, x, y, &sat, &val);
-        }
-      break;
-
-    case GTK_DIR_DOWN:
-      if (priv->focus_on_ring)
-        hue -= HUE_DELTA;
-      else
-        {
-          y += 1;
-          compute_sv (hsv, x, y, &sat, &val);
-        }
-      break;
-
-    case GTK_DIR_LEFT:
-      if (priv->focus_on_ring)
-        hue += HUE_DELTA;
-      else
-        {
-          x -= 1;
-          compute_sv (hsv, x, y, &sat, &val);
-        }
-      break;
-
-    case GTK_DIR_RIGHT:
-      if (priv->focus_on_ring)
-        hue -= HUE_DELTA
-          ;
-      else
-        {
-          x += 1;
-          compute_sv (hsv, x, y, &sat, &val);
-        }
-      break;
-
-    default:
-      /* we don't care about the tab directions */
-      break;
-    }
-
-  /* Wrap */
-  if (hue < 0.0)
-    hue = 1.0;
-  else if (hue > 1.0)
-    hue = 0.0;
-  
-  gtk_hsv_set_color (hsv, hue, sat, val);
-}
-
diff --git a/gtk/gtkhsv.h b/gtk/gtkhsv.h
deleted file mode 100644 (file)
index ae6bdb3..0000000
+++ /dev/null
@@ -1,116 +0,0 @@
-/* HSV color selector for GTK+
- *
- * Copyright (C) 1999 The Free Software Foundation
- *
- * Authors: Simon Budig <Simon.Budig@unix-ag.org> (original code)
- *          Federico Mena-Quintero <federico@gimp.org> (cleanup for GTK+)
- *          Jonathan Blandford <jrb@redhat.com> (cleanup for GTK+)
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
- */
-
-/*
- * Modified by the GTK+ Team and others 1997-2000.  See the AUTHORS
- * file for a list of people on the GTK+ Team.  See the ChangeLog
- * files for a list of changes.  These files are distributed with
- * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
- */
-
-#if !defined (__GTK_H_INSIDE__) && !defined (GTK_COMPILATION)
-#error "Only <gtk/gtk.h> can be included directly."
-#endif
-
-#ifndef __GTK_HSV_H__
-#define __GTK_HSV_H__
-
-#include <gtk/gtkwidget.h>
-
-G_BEGIN_DECLS
-
-#define GTK_TYPE_HSV            (gtk_hsv_get_type ())
-#define GTK_HSV(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_HSV, GtkHSV))
-#define GTK_HSV_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_HSV, GtkHSVClass))
-#define GTK_IS_HSV(obj)         (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_HSV))
-#define GTK_IS_HSV_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_HSV))
-#define GTK_HSV_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_HSV, GtkHSVClass))
-
-
-typedef struct _GtkHSV              GtkHSV;
-typedef struct _GtkHSVPrivate       GtkHSVPrivate;
-typedef struct _GtkHSVClass         GtkHSVClass;
-
-struct _GtkHSV
-{
-  GtkWidget parent_instance;
-
-  /*< private >*/
-  GtkHSVPrivate *priv;
-};
-
-struct _GtkHSVClass
-{
-  GtkWidgetClass parent_class;
-
-  /* Notification signals */
-  void (* changed) (GtkHSV          *hsv);
-
-  /* Keybindings */
-  void (* move)    (GtkHSV          *hsv,
-                    GtkDirectionType type);
-
-  /* Padding for future expansion */
-  void (*_gtk_reserved1) (void);
-  void (*_gtk_reserved2) (void);
-  void (*_gtk_reserved3) (void);
-  void (*_gtk_reserved4) (void);
-};
-
-
-GType      gtk_hsv_get_type     (void) G_GNUC_CONST;
-GtkWidget* gtk_hsv_new          (void);
-void       gtk_hsv_set_color    (GtkHSV    *hsv,
-                                double     h,
-                                double     s,
-                                double     v);
-void       gtk_hsv_get_color    (GtkHSV    *hsv,
-                                gdouble   *h,
-                                gdouble   *s,
-                                gdouble   *v);
-void       gtk_hsv_set_metrics  (GtkHSV    *hsv,
-                                gint       size,
-                                gint       ring_width);
-void       gtk_hsv_get_metrics  (GtkHSV    *hsv,
-                                gint      *size,
-                                gint      *ring_width);
-gboolean   gtk_hsv_is_adjusting (GtkHSV    *hsv);
-
-/* Convert colors between the RGB and HSV color spaces */
-void       gtk_hsv_to_rgb       (gdouble    h,
-                                gdouble    s,
-                                gdouble    v,
-                                gdouble   *r,
-                                gdouble   *g,
-                                gdouble   *b);
-void       gtk_rgb_to_hsv       (gdouble    r,
-                                gdouble    g,
-                                gdouble    b,
-                                gdouble   *h,
-                                gdouble   *s,
-                                gdouble   *v);
-
-G_END_DECLS
-
-#endif /* __GTK_HSV_H__ */